没想出来,看了官方给的题解才算懂了吧。 首先是通过后面的数字的长度,可以判断出是在10年以内,100年以内,1000年以内等等,然后保存下来末尾的数字,然后通过末位的数和在哪个范围内一直加,然后就可以判断出答案,官方给出的链接:http://codeforces.com/blog/entry/44408
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <sstream>
using namespace std;
inline void file()
{
freopen("D:\\go.txt", "r", stdin);
freopen("D:\\leave.txt", "w", stdout);
}
int main()
{
//file();
int cas;
scanf("%d", &cas);
while (cas--)
{
string str;
cin >> str;
str[3] = ' ';
stringstream tmp(str.substr(4));
int n;
tmp >> n;
int lenth = str.size() - 4;
int time_to = 0, t = 10;
//cout << lenth << endl;
for (int i = 1; i < lenth; ++i)
{
time_to += t;
t *= 10;
}
while (n < 1989 + time_to)//1989+time_to是一个模糊的范围
{
n += t;
//cout << n << endl;
}
printf("%d\n", n);
}
return 0;
}