2021年CCCC天梯赛题解——L1组
1.人与神
题意:让我们输出“To iterate is human, to recurse divine.”(和“hello,world!”没有什么区别)
思路:so easy级别的题,直接看代码!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
cout << "To iterate is human, to recurse divine." << endl;//输出语句
//or:puts(To iterate is human, to recurse divine.);
//or:printf("To iterate is human, to recurse divine.");
return 0;
}
2.两小时学完C语言
题意:给一个总数N,效率K,时间M,求剩余。
formula:
我们不妨设剩余字数为x;
则有:
x = N − ( K ∗ M ) x = N - (K * M) x=N−(K∗M)
转换为代码,则有:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
ll n,m,k;
int main()
{
cin >> n >> k >> m;
cout << (n - k * m) << endl;
return 0;
}
3.强迫症:
题意:
给我们一个出生日期的字符串,长度为4或6,转换并输出“年年年年-月月。”
做法:
1.当串长度为6时,输出前四位,再输出‘-’,最后输出后两位就好了
2.当串长度为4时,判断前两位年份是否小于22,是就加上20,否就加上19,再输出字符串的前两位,‘-’,以及月份。
如:9808—>19 + 98 + ‘-’ + 08
1998-08
如:1010—>20 + 10 + ‘-’ + 10
2010-10
code:
#include