标签:1.0 字符 %x ++ 实现 输入输出 ace val queue
基础练习 十六进制转八进制
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <cmath> 6 #include <stack> 7 #include <map> 8 #include <queue> 9 10 using namespace std; 11 12 int main() 13 { 14 int n; 15 scanf("%d", &n); 16 while(n --) 17 { 18 string str1, str2; 19 cin >>str1; 20 int len = str1.size(); 21 for (int i=0; i<len; ++i) { 22 if (str1[i] == ‘0‘) str2 += "0000"; 23 else if (str1[i] == ‘1‘) str2 += "0001"; 24 else if (str1[i] == ‘2‘) str2 += "0010"; 25 else if (str1[i] == ‘3‘) str2 += "0011"; 26 else if (str1[i] == ‘4‘) str2 += "0100"; 27 else if (str1[i] == ‘5‘) str2 += "0101"; 28 else if (str1[i] == ‘6‘) str2 += "0110"; 29 else if (str1[i] == ‘7‘) str2 += "0111"; 30 else if (str1[i] == ‘8‘) str2 += "1000"; 31 else if (str1[i] == ‘9‘) str2 += "1001"; 32 else if (str1[i] == ‘A‘) str2 += "1010"; 33 else if (str1[i] == ‘B‘) str2 += "1011"; 34 else if (str1[i] == ‘C‘) str2 += "1100"; 35 else if (str1[i] == ‘D‘) str2 += "1101"; 36 else if (str1[i] == ‘E‘) str2 += "1110"; 37 else if (str1[i] == ‘F‘) str2 += "1111"; 38 } 39 40 int len_ = str2.size(); 41 if (len_ % 3 == 1) str2 = "00" + str2; 42 if (len_ % 3 == 2) str2 = "0" +str2; 43 44 int len_now = str2.size(), flag = 0, temp; 45 for (int i = 0; i < len_now; i += 3) 46 { 47 temp = int(str2[i] - ‘0‘) * 4 + int(str2[i + 1] - ‘0‘) * 2 48 + int(str2[i + 2] - ‘0‘); 49 if (temp) flag = 1; 50 if (flag) printf("%d", temp); 51 } 52 printf("\n"); 53 } 54 return 0; 55 }
标签:1.0 字符 %x ++ 实现 输入输出 ace val queue
原文地址:https://www.cnblogs.com/GetcharZp/p/9033654.html