首页 > 其他 > 详细

HDU 2629 Identity Card

时间:2017-02-23 21:15:15      阅读:180      评论:0      收藏:0      [点我收藏+]

简单题

给出身份证号 判断住址 和出生年月

熟练字符串的操作 

主要是string::substr(s, l)//s:起始位置 l长度

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string>
 4 #include <string.h>
 5 #include <map>
 6 #include <fstream>
 7 
 8 using namespace std;
 9 
10 
11 map<string,string> m;
12 int main()
13 {
14     m["33"] = "Zhejiang";
15     m["11"] = "Beijing";
16     m["71"] = "Taiwan";
17     m["81"] = "Hong Kong";
18     m["82"] = "Macao";
19     m["54"] = "Tibet";
20     m["21"] = "Liaoning";
21     m["31"] = "Shanghai";
22     int T;
23     freopen("in.txt", "r", stdin);
24     ifstream cin ("in.txt");
25     scanf("%d", &T);
26     getchar();
27     while (T--)
28     {
29         char buff[128];
30         string id, from;
31         string yy, mm, dd;
32         gets(buff);
33         id = buff;
34         from = id.substr(0, 2);
35         yy = id.substr(6, 4);
36         mm = id.substr(10, 2);
37         dd = id.substr(12,2);
38         cout << "He/She is from " << m[from] << ",and his/her birthday is on " <<mm<<"," <<dd <<"," <<yy <<" based on the table."<<endl;
39     }
40 }

 

HDU 2629 Identity Card

原文:http://www.cnblogs.com/oscar-cnblogs/p/6435266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!