time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO’y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year’s competition.

For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO’9, IAO’0 and IAO’1, while the competition in 2015 received an abbreviation IAO’15, as IAO’5 has been already used in 1995.

You are given a list of abbreviations. For each of them determine the year it stands for.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.

Then n lines follow, each containing a single abbreviation. It’s guaranteed that each abbreviation contains at most nine digits.

Output

For each abbreviation given in the input, find the year of the corresponding Olympiad.

Examples

input

5

IAO’15

IAO’2015

IAO’1

IAO’9

IAO’0

output

2015

12015

1991

1989

1990

input

4

IAO’9

IAO’99

IAO’999

IAO’9999

output

1989

1999

2999

9999

【题解】



找规律;

左边对应数字范围;右边对应缩写的长度;

即缩写长度为x则在相应的左边范围内找;

这个范围很容易写出来的;

输出答案的时候每个范围也只要特判一下就能知道是具体哪个数字;

多个if用switch替代比较方便;

1989~1998 1

1999~2098 2

2099~3098 3

3099~13098 4

13099~113098 5

113099 1113098 6

1113099 11113098 7

11113099 111113098 8

111113099 1111113098 9

#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define LL long long using namespace std; int n;
string s; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} /*
1989~1998 1
1999~2098 2
2099~3098 3
3099~13098 4
13099~113098 5
113099 1113098 6
1113099 11113098 7
11113099 111113098 8
111113099 1111113098 9
*/ bool inrange(string s1,string s2,string s3)
{
return s1<=s2 && s2<=s3;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_int(n);
for (int i = 1;i <= n;i++)
{
cin >> s;
s.erase(0,4);
int len = s.size();
switch (len)
{
case 1:
{
if (s=="9")
puts("1989");
else
cout << "199" << s<<endl;
break;
}
case 2:
{
if (s=="99")
puts("1999");
else
cout << "20" << s<<endl;
break;
}
case 3:
{
if (inrange("099",s,"999"))
cout << "2"<<s<<endl;
else
cout << "3" << s<<endl;
break;
}
case 4:
{
if (inrange("3099",s,"9999"))
cout << s << endl;
else
cout << "1"<<s<<endl;
break;
}
case 5:
{
if (inrange("13099",s,"99999"))
cout << s<<endl;
else
cout << "1"<<s<<endl;
break;
}
case 6:
{
if (inrange("113099",s,"999999"))
cout << s << endl;
else
cout <<"1"<<s<<endl;
break;
}
case 7:
{
if (inrange("1113099",s,"9999999"))
cout << s<< endl;
else
cout << "1"<<s<<endl;
break;
}
case 8:
{
if (inrange("11113099",s,"99999999"))
cout << s<<endl;
else
cout << "1"<<s<<endl;
break;
}
case 9:
{
if (inrange("111113099",s,"999999999"))
cout <<s<<endl;
else
cout << "1"<<s<<endl;
break;
}
}
}
return 0;
}

【23.33%】【codeforces 664C】International Olympiad的更多相关文章

  1. codeforces 664C C. International Olympiad(数学)

    题目链接: C. International Olympiad time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【23.33%】【hdu 5945】Fxx and game

    Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...

  4. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  5. 【23. 合并K个排序链表】【困难】【优先队列/堆排序】

    合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...

  6. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

随机推荐

  1. redis 模糊删除实现

    redis 没有直接提供模糊删除的实现,我们可以根据现有的指令进行组合实现: import java.util.Arrays; import java.util.Set; import javax.a ...

  2. springboot 使用FreeMarker模板(转)

    在spring boot中使用FreeMarker模板非常简单方便,只需要简单几步就行: 1.引入依赖: <dependency> <groupId>org.springfra ...

  3. Java Lock Example – ReentrantLock(java锁的例子)

    Welcome to Java Lock example tutorial. Usually when working with multi-threaded environment, we use ...

  4. 从反编译深入理解JAVA内部类类结构以及finalkeyword

    1.为什么成员内部类能够无条件訪问外部类的成员? 在此之前,我们已经讨论过了成员内部类能够无条件訪问外部类的成员,那详细到底是怎样实现的呢?以下通过反编译字节码文件看看到底.其实,编译器在进行编译的时 ...

  5. [D3] SVG Graphics Containers and Text Elements in D3 v4

    SVG is a great output format for data visualizations because of its scalability, but it comes with s ...

  6. 从零开始使用git第一篇:下载安装配置

    从零开始使用git 第一篇:下载安装配置 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:git撤销操作.分支操作和 ...

  7. 使用前端后台管理模板库admin-lte(转)

    使用前端后台管理模板库admin-lte 使用前端后台管理模板库admin-lte 安装 搭建环境 安装 安装admin-lte,可以通过以下几种办法安装,下图是GitHub中admin-lte的主页 ...

  8. Ehcache与Memcache的差别

    ehcache是纯java编写的.通信是通过RMI方式,适用于基于java技术的项目. memcachedserver端是c编写的.client有多个语言的实现,如c.php(淘宝.sina等各大门户 ...

  9. 15、USB摄像头图片采集+QT显示

    一.Qt的下载和的安装 关于Qt的安装,网络上有很详细的介绍.这里只做简单介绍. 需要的安装包一共有两个:Qt Creator 和QTE. 1)QT Creator 下载地址:qt-sdk-linux ...

  10. 【t043】成绩查询

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 说起测试计算机的软件,排在第一位的就应当是SuperPi 了.它不但能良好的体现机器的整体水平,而且还 ...