Identity Card

来源:互联网 发布:mac安装错误字体会怎样 编辑:程序博客网 时间:2024/06/05 05:35
#include "stdafx.h"
#include<iostream>
using namespace std;
#include<iomanip>
#include <string>  


int main()  
{  
    int n,i;
string ID,WW;
int W,yy,mm,dd;
cin >> n; 
for(i=0;i<n;i++)
{
cin>>ID;
W=atoi(ID.substr(0,2).c_str());
if(W==33)WW="Zhejiang";
else if(W==11)WW="Beijing";
else if(W==71)WW="Taiwan";
else if(W==81)WW="Hong Kong";
else if(W==82)WW="Macao";
else if(W==54)WW="Tibet";
else if(W==21)WW="Liaoning";
else WW="Shanghai";
yy=atoi(ID.substr(6,4).c_str());
mm=atoi(ID.substr(10,2).c_str());
dd=atoi(ID.substr(12,2).c_str());
cout<<"He/She is from "<<WW<<",and his/her birthday is on ";
if(mm<10)
cout<<"0"<<mm<<",";
else
cout<<mm<<",";
if(dd<10)
cout<<"0"<<dd<<","<<yy<<" based on the table."<<endl;
else
cout<<dd<<","<<yy<<" based on the table."<<endl;
}
system("Pause");
    return 0;  
}  


本题也是较为简单的,就是考察队字符串转int的处理,其中substr中第一个参数是起始位置,第二个参数表示长度,刚开始我以为第二个表示终点位置而弄错了。其次就是刚开始简单的把处理出来的数字显示输出。后来才想到月和日其中低于10时前面是默认没有0了,所以需要特别添加0
0 0
原创粉丝点击