HDOJ-2629

题目描述
在这里插入图片描述补充知识
(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;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值