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
#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
- Identity Card
- Identity Card
- Identity Card
- Identity Card
- 杭电 Identity Card
- HDU2629:Identity Card
- 1409210819-hd-Identity Card
- HDOJ 2629 Identity Card
- 2629 Identity Card
- 八、Identity Card
- HDU2629 Identity Card
- 水题hdu Identity Card
- HDOJ 2629 Identity Card
- hdoj 2629 Identity Card【操蛋题】
- HDOJ_ACM_steps——Identity Card
- HDU 1.2.7 Identity Card
- acm steps1.2.8(Identity Card)
- hdu 2629 Identity Card (模拟)
- 第一篇 如何安装和设置Cocos Code IDE
- Ubuntu 12.04下无法切换中文输入法的解决方法
- Win32 路径操作API
- perl 大小写字母转换
- 致命错误: zlib.h:没有那个文件或目录
- Identity Card
- Java坦克大战 (二) 之画一个能动的圆圈代表坦克
- java web项目中所遇到的编码问题
- css3美化文本框提示特效代码下载
- 常用的工具类
- java线程:线程的同步-同步方法
- 习题8
- hive sql遇到的问题
- windbg 调试 r3 死循环