GPLT练习集 L1 73--80
L1-073 人与神 (5 分)
题目描述
跨界大神 L. Peter Deutsch 有一句名言:“To iterate is human, to recurse divine.”(迭代的是人,递归的是神).本题就请你直接在屏幕上输出这句话
输入格式:
本题没有输入。
输出格式:
在一行中输出 To iterate is human, to recurse divine.。
输入样例:
无
输出样例:
To iterate is human, to recurse divine.
代码
#include<iostream>
using namespace std;
int main()
{
cout<<"To iterate is human, to recurse divine.";
return 0;
}
L1-074 两小时学完C语言 (5 分)
题目描述
输入格式:
输入在一行中给出 3 个正整数,分别是 N(不超过 400 000),教科书的总字数;K(不超过 3 000),是宝宝每分钟能看的字数;M(不超过 120),是宝宝看书的分钟数。
题目保证宝宝看完的字数不超过 N。
输出格式:
在一行中输出宝宝还没有看的字数。
输入样例:
100000 1000 72
输出样例:
28000
代码
#include <iostream>
using namespace std;
int main() {
int n,k,m;
cin>>n>>k>>m;
cout<<n-(k*m);
return 0;
}
L1-075 强迫症 (10 分)
题目描述
小强在统计一个小区里居民的出生年月,但是发现大家填写的生日格式不统一,例如有的人写 199808,有的人只写 9808。有强迫症的小强请你写个程序,
把所有人的出生年月都整理成 年年年年-月月 格式。对于那些只写了年份后两位的信息,我们默认小于 22 都是 20 开头的,其他都是 19 开头的。
输入格式:
输入在一行中给出一个出生年月,为一个 6 位或者 4 位数,题目保证是 1000 年 1 月到 2021 年 12 月之间的合法年月。
输出格式:
在一行中按标准格式 年年年年-月月 将输入的信息整理输出。
输入样例 1:
9808
输出样例 1:
1998-08
输入样例 2:
0510
输出样例 2:
2005-10
输入样例 3:
196711
输出样例 3:
1967-11
代码
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
if(s.size() == 6)
cout << s.substr(0,4) << "-" << s.substr(4,2);
else {
if(stoi(s.substr(0,2)) < 22)
cout <<"20"<< s.substr(0,2) << "-" << s.substr(2);
else
cout <<"19"<< s.substr(0,2) << "-" << s.substr(2);
}
return 0;
}
/*
思路:
1.判断其长度;
2长度为6,substr()截取至4;
3.长度为4,判断stoi(s.substr(0,2)) < 22;
*/
L1-076 降价提醒机器人
题目描述
代码
#include <iostream>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
while(n--) {
double p;
cin>>p;
if(p<m)
printf("On Sale! %.1lf\n",p);
}
return 0;
}
L1-077 大笨钟的心情 (15 分)
题目描述
代码
#include <iostream>
using namespace std;
int main() {
int num[101],digit,j=0;
for(int i=0 ; i<24 ; i++)
cin>>num[i];
while(cin>>digit) {
if(digit<0 || digit>23)
break;
if(num[digit]>50)
cout<<num[digit]<<" Yes"<<endl;
else
cout<<num[digit]<<" No"<<endl;
}
return 0;
}
L1-078 吉老师的回归 (15 分)
题目描述
输入样例 1:
5 1
L1-1 is a qiandao problem.
L1-2 is so...easy.
L1-3 is Easy.
L1-4 is qianDao.
Wow, such L1-5, so easy.
输出样例 1:
L1-4 is qianDao.
输入样例 2:
5 4
L1-1 is a-qiandao problem.
L1-2 is so easy.
L1-3 is Easy.
L1-4 is qianDao.
Wow, such L1-5, so!!easy.
输出样例 2:
Wo AK le
代码
#include <iostream>
#include<cstring>
using namespace std;
int main() {
int n,m,i=0;
cin>>n>>m;
getchar();
while(n--) {
string s;
getline(cin,s);
if(s.find("qiandao")==-1 && s.find("easy")==-1) {
i++;
if(i == m+1)
cout<<s<<endl;
}
}
if(m>=i)
cout<<"Wo AK le";
return 0;
}
L1-079 天梯赛的善良 (20 分)
题目描述
天梯赛是个善良的比赛。善良的命题组希望将题目难度控制在一个范围内,使得每个参赛的学生都有能做出来的题目,并且最厉害的学生也要非常努力才有可能得到高分。
于是命题组首先将编程能力划分成了 1 0 6 10^6 106个等级(太疯狂了,这是假的),然后调查了每个参赛学生的编程能力。现在请你写个程序找出所有参赛学生的最小和最大能力值,给命题组作为出题的参考。
输入格式:
输入在第一行中给出一个正整数 N(≤
2
×
1
0
4
2×10^4
2×104 ),即参赛学生的总数。随后一行给出 N 个不超过
1
0
6
10 ^6
106的正整数,是参赛学生的能力值。
输出格式:
第一行输出所有参赛学生的最小能力值,以及具有这个能力值的学生人数。第二行输出所有参赛学生的最大能力值,以及具有这个能力值的学生人数。同行数字间以 1 个空格分隔,行首尾不得有多余空格。
输入样例:
10
86 75 233 888 666 75 886 888 75 666
输出样例:
75 3
888 2
代码
#include <bits/stdc++.h>
using namespace std;
const int MAX = 30000;
int n,num[MAX],j,k;
int main() {
cin >> n;
for(int i = 0 ; i < n ; ++i)
cin >> num[i];
sort(num,num + n);
for(int i = 0 ; i < n ; ++i) {
if(num[i] != num[0]) break;
++j;
}
for(int i = n-1 ; i >= 0 ; --i) {
if(num[i] != num[n-1]) break;
++k;
}
cout << num[0] << " " << j << endl;
cout << num[n-1] << " " << k << endl;
return 0;
}
L1-080 乘法口诀数列 (20 分)
题目描述
本题要求你从任意给定的两个
1
1
1 位数字
a
1
a_1
a1和
a
2
a_2
a2开始,用乘法口诀生成一个数列{
a
n
a_n
an},规则为从
a
1
a_1
a1开始顺次进行,每次将当前数字与后面一个数字相乘,将结果贴在数列末尾。如果结果不是
1
1
1位数,则其每一位都应成为数列的一项。
输入格式:
输入在一行中给出
3
3
3个整数,依次为
a
1
,
a
2
a_1,a_2
a1,a2和
n
n
n,满足 0≤
a
1
,
a
2
a_1,a_2
a1,a2 ≤9,0<n≤
1
0
3
.
10^3.
103.
输出格式:
在一行中输出数列的前
n
n
n项。数字间以
1
1
1个空格分隔,行首尾不得有多余空格。
输入样例:
2 3 10
输出样例:
2 3 6 1 8 6 8 4 8 4
样例解释:
数列前 2 项为 2 和 3。从 2 开始,因为 2×3=6,所以第 3 项是 6。因为 3×6=18,所以第 4、5 项分别是 1、8。依次类推…… 最后因为第 6 项有 6×8=48,对应第 10、11 项应该是 4、8。而因为只要求输出前 10 项,所以在输出 4 后结束。
代码
#include <bits/stdc++.h>
using namespace std;
string a,b;
int main() {
cin >> a >> b;
int i = 0 ;
int n;
cin >> n;
string s = a + b;
while(s.size() < n) {
s += to_string((s[i]-'0')*(s[i+1]-'0'));
//自动将其分解成单一字符
++i;
}
for(int i = 0 ; i < n ; ++i)
cout << s[i] <<" \n"[i == n-1];
return 0;
}