杭电oj2629

2629根据身份证号辨别所在地和生日按照以下形式输出
He/She is from Zhejiang,and his/her birthday is on 10,12,1989 based on the table.
思路:身份证长度以及信息所在位置是固定的,用字符串截取函数截取出生日信息以及地址信息,根据switch找到地点,最后按格式输出,注意空格
若用string: 截取函数为substr
string s=“1234”;
s.substr(2) //从字符串下标为2的地方开始截取,截取到末尾
s.substr(0,2) //从字符串下标为2的地方开始截取,截取长度为2,
s.substr(1,2) //输出23
若用字符数组:
取字符串s1中的前n 个字符串,赋值给s2;
s2=strncpy(s2,s1, n);

#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m;
	cin>>n;
	while(n--){
	string str;
	string str1,year,mon,day;
	string des;
	cin>>str;
	str1=str.substr(0,2);//截取地址信息 
	year=str.substr(6,4);//生日年份信息 
	mon=str.substr(10,2);//生日月份信息 
	day=str.substr(12,2);//生日信息 
	int n=(str1[0]-'0')*10+str1[1]-'0';
	switch(n){
		 case 33: des="Zhejiang";
	        break;
	  case 11: des="Beijing";
	        break;
	  case 71: des="Taiwan";
	        break;
	  case 81: des="Hong Kong";
	        break;
	  case 82: des="Macao";
	        break;
	  case 54: des="Tibet";
	        break;
	  case 21: des="Liaoning";
	        break;
	  case 31: des="Shanghai";
	        break;
	
	}
	cout<<"He/She is from "<<des<<",and his/her birthday is on ";
	 cout<<mon<<","<<day<<","<<year<<" based on the table."<<endl;
	 
	 }
	 
	return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值