题目描述
补充知识
(1)字符串的截取 s.substr();
#include<string>
#include<iostream>
using namespace std;
int main()
{
string x="0123456789";
cout<<x.substr()<<endl; //默认全部字符, 输出:0123456789
cout<<x.substr(5)<<endl;//截取从下标5开始到结尾的全部字符, 输出:56789
cout<<x.substr(0,5)<<endl;//从下标为0开始向后截取5位, 输出: 01234
}
解题思路
#include<iostream>
#include<string>
using namespace std;
struct id{
string city;
string no;
id(){}
id(string _city,string _no){
city=_city;
no=_no;
}
};
//结构体的赋值
id pp[8]={{"Zhejiang","33"},{"Beijing","11"},{"Taiwan","71"},
{"Hong Kong","81"},{"Macao","82"},{"Tibet","54"},
{"Liaoning","21"},{"Shanghai","31"}};
int main()
{
int n;
cin>>n;
string str;
for(int i=0;i<n;i++)
{
cin>>str;
for(int i=0;i<8;i++)
{
if(str.substr(0,2)==pp[i].no)
{
cout<<"He/She is from "<<pp[i].city;
cout<<",and his/her birthday is on ";
cout<<str[10]<<str[11]<<','<<str[12]<<str[13]<<','<<str[6]<<str[7];
cout<<str[8]<<str[9]<<" based on the table."<<endl;
}
}
}
return 0;
}