标签:names else def div space default ase out pac
在2-8进制转换时注意后三位处理即可
#include <iostream> #include <string> using namespace std; int main() { int n,i; cin>>n; while(n--) { int num=0; string a="",b; cin>>a; b=""; for(i=0;i<a.length();i++) { switch(a[i]) { case ‘0‘:b+="0000";break; case ‘1‘:b+="0001";break; case ‘2‘:b+="0010";break; case ‘3‘:b+="0011";break; case ‘4‘:b+="0100";break; case ‘5‘:b+="0101";break; case ‘6‘:b+="0110";break; case ‘7‘:b+="0111";break; case ‘8‘:b+="1000";break; case ‘9‘:b+="1001";break; case ‘A‘:b+="1010";break; case ‘B‘:b+="1011";break; case ‘C‘:b+="1100";break; case ‘D‘:b+="1101";break; case ‘E‘:b+="1110";break; case ‘F‘:b+="1111";break; default:break; } } int flag=0; if(b.length()%3==1){ b.insert(0,"00"); }else if(b.length()%3==2){ b.insert(0,"0"); } for(i=0;i<=b.length()-3;i+=3){ num=4*(b[i]-‘0‘)+2*(b[i+1]-‘0‘)+(b[i+2]-‘0‘); if(num) flag=1; if(flag) cout<<num; } cout<<endl; } }
标签:names else def div space default ase out pac
原文地址:https://www.cnblogs.com/joker99/p/12221374.html