C++ 代码
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
string Data;
vector<string> str={
"Jan","Feb","Mar",
"Apr","May","Jun",
"Jul","Aug","Sep",
"Oct","Nov","Dec"
};
int main(){
getline(cin,Data);//获取整行string
string month=Data.substr(0,3);//substr 获取从0位开始3位的字符串
for(int i=0;i<12;i++){
if(!month.compare(str[i])) cout<<i+1; //string1.compare(string2) 比对完整的string1 和 string2
}
string day=Data.substr(3); //获取从第三位开始的子串
if(day[0]=='0')cout<<" "<<day[1];
else cout<<" "<<day;
return 0;
}
自认为比其他一长段的好理解多了
$\Huge\color{#00FF7F}{赞!帮助我顺便复习了下substr的用法。}$