【23.33%】【codeforces 664C】International Olympiad
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的更多相关文章
- codeforces 664C C. International Olympiad(数学)
题目链接: C. International Olympiad time limit per test 1 second memory limit per test 256 megabytes inp ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【hdu 5945】Fxx and game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【23. 合并K个排序链表】【困难】【优先队列/堆排序】
合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.33%】【codeforces 552D】Vanya and Triangles
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
随机推荐
- amazeui学习笔记--css(布局相关2)--等分网格 AVG Grid
amazeui学习笔记--css(布局相关2)--等分网格 AVG Grid 一.总结 1.与grid区别:网格中:am-g + am-u-xx-n 等分网格中只有一个: am-avg-sm-4(在u ...
- iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 12.SpringBoot+MyBatis(XML)+Druid
转自:https://www.cnblogs.com/MaxElephant/p/8108342.html 主要是在Spring Boot中集成MyBatis,可以选用基于注解的方式,也可以选择xml ...
- 利用OBJECT_DEFINITION函数来代码存档
作为一名数据库管理员,在进行代码迁移之前,总是尽力给提交于开发环境的代码一个完整的面貌.但是,不得不承认,我不能保证不发生任何可能破坏开发系统的事情.当这种情况发生时,可能的补救措施是恢复到目标代码的 ...
- 希捷硬盘扩容软件-----DiscWizard
SeagateDiscWizard可为Seagate磁盘驱动器的使用提供便利.DiscWizard可帮助您迅速安装新的磁盘驱动器.并通过安装向导指导您在磁盘驱动器上完毕分区的创建和格式化. DiscW ...
- dataTable() 与 DataTable() 的差别与处理方式
jQuery dataTable的初始化有两种方式: var dataTable = $('#example').dataTable(); 与 var DataTable = $('#example' ...
- hdu2049(组合数学)
题意:每位新娘打扮得差点儿一模一样,并盖上大大的红盖头随机坐成一排;然后,让各位新郎寻找自己的新娘.每人仅仅准找一个,而且不同意多人找一个.最后,揭开盖头,如果找错了对象就要当众跪搓衣板...如果一共 ...
- 内存、时间复杂度、CPU/GPU以及运行时间
衡量 CPU 的计算能力: 比如一个 Intel 的 i5-2520M @2.5 Ghz 的处理器, 则其计算能力 2.5 * 4(4核) = 10 GFLOPS FLOP/s,Floating-po ...
- 在 AppDelegate 设置屏幕切换
//禁止横屏显示 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWin ...
- PHP解决约瑟夫环问题
PHP解决约瑟夫环问题 一.总结 二.PHP解决约瑟夫环问题 约瑟夫环(约瑟夫问题)是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到 ...