【23.33%】【codeforces 664C】International Olympiad
来源:互联网 发布:淘宝三哥家店名叫什么 编辑:程序博客网 时间:2024/06/16 19:25
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 longusing 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
- Codeforces 664C:International Olympiad
- CodeForces 664 C.International Olympiad(构造)
- C. International Olympiad
- codeforces round#347 div2 C International Olympiad 想法题
- codeforces 662D International Olympiad
- Codeforces 662D International Olympiad【贪心】
- Codeforces Round #347 (Div. 1) B. International Olympiad
- Codeforces Round #347 (Div. 2) C. International Olympiad(求第一次出现这种数字结尾的是哪一个年份)
- CF #347 (Div.2) C. International Olympiad(模拟)
- cf664C. International Olympiad
- codeforces_664C. International Olympiad
- CodeForces 222D Olympiad
- CodeForces 222D Olympiad
- Codeforces Team Olympiad(暴力)
- CodeForces 222D Olympiad
- 【CODEFORCES】 A. Team Olympiad
- CodeForces 490A Team Olympiad
- 第十四章 个人渣翻译 spf13插件---NERDCommenter 使用教程
- Medium 277题 Find the Celebrity
- 1.第一章,数据的处理
- Python4--登录知乎
- 第22课: Scala集合和高级函数操作实战及Spark源码鉴赏
- 【23.33%】【codeforces 664C】International Olympiad
- 个人网站已经建立(目前暂时用模板,个人网站正在筹备)
- 安装配置Apache2.4和php7.0
- 利用链表构建队列(100)
- MySQL密码重置
- 小猫统计:结合正则表达式整理word格式,导入到小猫统计数据库
- 实现多线程断点下载可以运行
- A*算法程序
- Ora-12518 TNS:监听程序无法分发客户机