#include <string> #include <iostream> using namespace std; //给一个字符串,都是十六进制表示的 //都是十六进制表示的,其中有两个需要转码 //A->12 34 //B->AB CD //7 1 2 3 4 5 A B //9 1 2 3 4 5 12 34 AB CD //第一个数字记录个数,也为十六进制 //十六进制转换函数 string toHex(int num) { //知道商为0为止 string result = ""; while(num) { int temp = num % 16; num = num / 16; string temp_s; if (temp < 10) { temp_s = to_string(temp); } else  { temp_s = (temp - 10) + 'A'; } result = temp_s + result; } return result; } int main() { string num; cin >> num; string str; string result = ""; int number = stoi(num); while (cin >> str) { if (str == "A") { str = "12 34"; number++; } if (str == "B") { str = "AB CD"; number++; } //如果是其他的字符则维持原状 result = result+" "+str; } //接下来要把number这个数字转换为十六进制 string s = toHex(number); result = s + result; cout << result << endl; system("pause"); return 0; }//报文转发啊
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务