#include<stdio.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { char id[20]; scanf("%s", id); int x = (id[1] - 48)*(id[0] - 48); switch (x) { case 9:printf("He/She is from Zhejiang,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 1:printf("He/She is from Beijing,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 7:printf("He/She is from Taiwan,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 8:printf("He/She is from Hong Kong,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 16:printf("He/She is from Macao,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 20:printf("He/She is from Tibet,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 2:printf("He/She is from Liaoning,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; case 3:printf("He/She is from Shanghai,and his/her birthday is on %c%c,%c%c,%c%c%c%c based on the table.\n", id[10], id[11], id[12], id[13], id[6], id[7], id[8], id[9]); break; } } return 0; }
这题代码很难看,本来是想用switch判断给一个字符数组具体省份的名称,结果发现自己数组用的还不太熟。等我下午好好看看字符数组这一块后再来更新代码。