ZJU PAT 1027 Colors in Mars
生活随笔
收集整理的這篇文章主要介紹了
ZJU PAT 1027 Colors in Mars
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
http://pat.zju.edu.cn/contests/pat-practise/1027
繼續無聊。
數制轉換一定不要忘了0.
1 #include <stdio.h> 2 #include <stack> 3 using namespace std; 4 void trans(int dig) 5 { 6 if(dig == 0){ 7 printf("00"); 8 return; 9 } 10 stack<char> S; 11 while(dig){ 12 int temp=dig%13; 13 if(temp>=10){ 14 S.push('A'+temp-10); 15 } else { 16 S.push(temp+'0'); 17 } 18 dig/=13; 19 } 20 if(S.size()==1){ 21 S.push('0'); 22 } 23 24 while(!S.empty()){ 25 putchar(S.top()); 26 S.pop(); 27 } 28 29 } 30 int main() 31 { 32 int i=0; 33 int dig; 34 for(;i<3;i++){ 35 scanf("%d",&dig); 36 if(i==0) putchar('#'); 37 trans(dig); 38 } 39 putchar('\n'); 40 }轉載于:https://www.cnblogs.com/yangce/archive/2012/04/15/2449019.html
總結
以上是生活随笔為你收集整理的ZJU PAT 1027 Colors in Mars的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对Flush原理的个人理解
- 下一篇: 给程序员的VIM速查卡