十六进制转化+暴力的方法,超级简单!
//一定注意,两个二进制位才表示一个字节,8个二进制位一个字节。
//一个16进制位等于4个二进制位。所以8个二进制位需要2个16进制位!
#include <stdio.h>
int main(void)
{
int c;
int i, j;
int ch[100][101];
int value;
int n;
scanf("%d", &n);
getchar(); //屏蔽多输入的空格键
for(j = 0; j < n; j++) {
i = 0;
while((c = getchar()) != '\n') {
ch[j][i++] = c;
}
ch[j][i] = '\n';
}
for(j = 0; j < n; j++) {
i = 0;
while(ch[j][i] != '\n') {
value = ch[j][i] * 0x100 + ch[j][i+1];
if(value >= 0xb0a1 && value < 0xb0c5) {
putchar('A');
} else if(value < 0xb2c1) {
putchar('B');
} else if(value < 0xb4ee) {
putchar('C');
} else if(value < 0xb6ea) {
putchar('D');
} else if(value < 0xb7a2) {
putchar('E');
} else if(value < 0xb8c1) {
putchar('F');
} else if(value < 0xb9fe) {
putchar('G');
} else if(value < 0xbbf7) {
putchar('H');
} else if(value < 0xbfa6) {
putchar('J');
} else if(value < 0xc0ac) {
putchar('K');
} else if(value < 0xc2e8) {
putchar('L');
} else if(value < 0xc4c3) {
putchar('M');
} else if(value < 0xc5b6) {
putchar('N');
} else if(value < 0xc5be) {
putchar('O');
} else if(value < 0xc6da) {
putchar('P');
} else if(value < 0xc8bb) {
putchar('Q');
} else if(value < 0xc8f6) {
putchar('R');
} else if(value < 0xcbfa) {
putchar('S');
} else if(value < 0xcdda) {
putchar('T');
} else if(value < 0xcef4) {
putchar('W');
} else if(value < 0xd1b9) {
putchar('X');
} else if(value < 0xd4d1) {
putchar('Y');
} else {
putchar('Z');
}
i += 2;;
}
putchar('\n');
}
}
Map+比较函数,稍微复杂一点,map本来我也想到了的,但是一直纠结16进制怎么打印出来。。
//这一题应该用Map啊!其实应该想到的,只是不太会两个字节的比较,像十进制那样比较就好了啊!
//之前一直纠结怎么把中文字的16进制打印出来,问题是不需要打印啊,
#include<cstdio>
/*Copy Right By qianshou: http://blog.csdn.net/qsyzb*/
#include<iostream>
#include<cstring>
using namespace std;
string a[2][23]={{"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"},
{"啊","芭","擦","搭","蛾","发","噶","哈","击","喀","垃","妈","拿","哦","啪","期","然","撒","塌","挖","昔","压","匝"}};
string search(string &temp)
{
for(int i=1;i<24;i++)
{
if(temp>a[1][i-1])continue;
else return a[0][i-2];
}
}
string fun(string &str)
{
int len = str.length();
string result = "";
for(int i=0;i<len;i+=2)
{
string temp = str.substr(i,2);
result += search(temp);
}
return result;
}
int main()
{
int n;
string str;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>str;
cout<<fun(str)<<endl;
}
return 0;
}