II:十進制到八進制

總時間限制: 
1000ms
 
內存限制: 
65536kB
描述

把一個十進制正整數轉化成八進制。ios

輸入
一行,僅含一個十進制表示的整數a(0 < a < 65536)。
輸出
一行,a的八進制表示。
樣例輸入
9
樣例輸出
11
 1 //無腦法吧
 2 #include <iostream>
 3 #include<cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7     int a;
 8     cin >> a;
 9     printf("%o", a);
10     return 0;
11 }
 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 int main()
 5 {
 6     const int size=6;
 7     char a[size];
 8     cin>>a;
 9     int remainder[size],result,temp=0;
10     int len=strlen(a);
11     for(int k=0;k<len;k++)
12     {
13         temp*=10;
14         temp+=a[k]-'0';
15     }
16     result=temp;
17     int i=0;
18     while(result!=0)
19     {
20         remainder[i]=result%8;
21         result/=8;
22         ++i;
23     }
24 
25     for(i=i-1;i>=0;i--)
26         cout<<remainder[i];
27     cout<<endl;
28 
29     return 0;
30 }
相關文章
相關標籤/搜索