✨ 只需要判断 年 是否大于200年,如果多一天或者多一个月都是大于200,(多的天数和月数的总和是不可能大于一年的),所以只需要加减来判断最后的总和
✨ 字符的拆分,借鉴的博客:戳戳戳~
里面有很多自带的函数,尤其是操作的函数的参数
✨ 输入时,在读取完人名之后会读取到一个空格,当时去搜索了做法:getcin(但是没用起来…最后还是用数组下标操作起来的)
✨ 还要注意vector用法
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<vector>
using namespace std;
vector<string> split(const string &s,const string & dim){
vector<string> vec;
if(s == "") return vec;
char *c = new char[s.length()+1];
strcpy(c,s.c_str());//将string转换为char
char *d = new char[dim.length()+1];
strcpy(d,dim.c_str());
char *p = strtok(c,d);
while(p){
string s1 = p;
vec.push_back(s1);
p = strtok(NULL, d);
}
return vec;
}
int main(){
int num;
cin>>num;
string s1[2*num];
for(int i=0;i<num;i++){
cin>>s1[2*i]>>s1[2*i+1];
// cout<<s1[i]<<endl;
}
int year =2014;
int mon = 9;
int day = 6;
int count1 = 0;
string dim = "/";
int maxage =0;
int minage = 1000;
string maxname = "";
string minname = "";
for(int i=0;i<num;i++){
string s = s1[2*i+1];
vector<string> temp = split(s,dim);
//cout<<temp[0]<<" "<<temp[1]<<" "<<temp[2]<<endl;
// int m =(temp[0][0]-'0')*1000+(temp[0][1]-'0')*100+(temp[0][2]-'0')*10+(temp[0][3]-'0');
//cout<<m<<endl;
if(temp[0][0]-'0' >year||(temp[0][0]-'0'==year&&temp[1][0]-'0'>mon)||(temp[0][0]-'0'==year&&temp[1][0]-'0'==mon&&temp[2][0]-'0'>day)){
}else {
int y = year-((temp[0][0]-'0')*1000+(temp[0][1]-'0')*100+(temp[0][2]-'0')*10+(temp[0][3]-'0'));
int m = mon-((temp[1][0]-'0')*10+(temp[1][1]-'0'));
int d = day - ((temp[2][0]-'0')*10+(temp[2][1]-'0'));
if(y+m+d<=200&y+m+d>=0){
if(y+m+d>maxage){
maxage = y+m+d;
maxname = s1[2*i];
}
if(y+m+d<minage){
minage = y+m+d;
minname = s1[2*i];
}
count1++;
}
}
}
cout<<count1<<" "<<maxname<<" "<<minname<<endl;
}