题目链接:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=2&problemid=25
好的吧,不得不说我因为一个Hone Kong卡了好几个小时,改来改去,使用了几种方式:1,使用hashmap保存所有的表格的数据,将身份证头两位、年、月、日转换成整数。2,使用hashmap只转换头两位,其余直接从身份证中取。3,纯粹使用网上的方法,直接将身份证的字符串输出,都是wrong answer,直到使用文本比较工具才发现了错误,233333333~~~。
代码如下:
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
char* arr[100];
void init(){
arr[33]="Zhejiang";
arr[11]="Beijing";
arr[71]="Taiwan";
arr[81]="Hong Kong";
arr[82]="Macao";
arr[54]="Tibet";
arr[21]="Liaoning";
arr[31]="Shanghai";
}
int main(){
int n;
init();
cin>>n;
while(n--){
char str[100];
scanf("%s",str);
int h=(str[0]-'0')*10+(str[1]-'0');
int year = (str[6]-'0')*1000+(str[7]-'0')*100+(str[8]-'0')*10+(str[9]-'0');
int month = (str[10]-'0')*10+(str[11]-'0');
int day=(str[12]-'0')*10+(str[13]-'0');
printf("He/She is from %s,and his/her birthday is on %02d,%02d,%04d based on the table.\n",
arr[h],month,day,year);
}
return 0;
}
转载于:https://www.cnblogs.com/jackwuyongxing/p/4524507.html