标签:str1 main char nbsp turn include std bsp roman
Input
一下T行 每行一个八进制数字串s
Output
Sample Input
Sample Output
#include<iostream>
#include<string>
using namespace std;
char x(int n){
if(n<=9)
return n+‘0‘;
switch(n){
case 10:return ‘A‘;
case 11:return ‘B‘;
case 12:return ‘C‘;
case 13:return ‘D‘;
case 14:return ‘E‘;
case 15:return ‘F‘;
}
}
int main(){
int t,i,num,n1,n2,n3,j,k;
string str;
char str1[10000];
cin>>t;
while(t--){
str.clear();
j=0;
cin>>str;
i=str.size()-1;
for(;i>3;i-=4){
num=str[i]-‘0‘+(str[i-1]-‘0‘)*8+(str[i-2]-‘0‘)*64+(str[i-3]-‘0‘)*512;
n1=0,n2=0,n3=0;
while(num>0){
if(num>=16*16){
num-=16*16;
n1++;
}
else if(num>=16){
num-=16;
n2++;
}
else{
n3=num;
break;
}
}
str1[j++]=x(n3);
str1[j++]=x(n2);
str1[j++]=x(n1);
}
num=0,n1=0,n2=0,n3=0;
for(k=0;k<=i;++k)
num=num*8+str[k]-‘0‘;
while(num>0){
if(num>=16*16){
num-=16*16;
n1++;}
else if(num>=16){
num-=16;
n2++;}
else{
n3=num;
break;}
}
str1[j++]=x(n3);
str1[j++]=x(n2);
str1[j++]=x(n1);
if(n1==0){
j--;
if(n2==0)
j--;
}
while(--j)
cout<<str1[j];
cout<<str1[j]<<endl;
}
return 0;
}
标签:str1 main char nbsp turn include std bsp roman
原文地址:http://www.cnblogs.com/xuyt/p/6925732.html