L1-001. Hello World

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

这道超级简单的题目没有任何输入。

你只需要在一行中输出著名短句“Hello World!”就可以了

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;int main()
{printf("Hello World!\n");return 0;
}

L1-002. 打印沙漏

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印

************
*****

所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。

给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。

输入格式:

输入在一行给出1个正整数N(<=1000)和一个符号,中间以空格分隔。

输出格式:

首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。

输入样例:

19 *

输出样例:

************
*****
2
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;int n, sy;
char c;int geth()
{int a[1010] = {0, 1};int s = 1;for(int i = 2; i < 50; i++){a[i] = a[i-1] + 2;s += a[i] * 2;if(n < s){sy = n - (s-a[i]*2);return i-1;}}
}int main()
{scanf("%d %c", &n, &c);int h = geth(), kg = 0;for(int i = h; i >= 1; i--){for(int k = 0; k < kg; k++) printf(" ");kg++;for(int k = 0; k < i * 2 - 1; k++) printf("%c", c);printf("\n");}kg-=2;for(int i = 2; i <= h; i++){for(int k = 0; k < kg; k++) printf(" ");kg--;for(int k = 0; k < i * 2 - 1; k++) printf("%c", c);printf("\n");}printf("%d\n", sy);return 0;
}

L1-003. 个位数统计

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。

输入格式:

每个输入包含1个测试用例,即一个不超过1000位的正整数N。

输出格式:

对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。要求按D的升序输出。

输入样例:

100311

输出样例:

0:2
1:3
3:1
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;int main()
{char s[1010];int a[11] = {0};scanf("%s", s);for(int i = 0; s[i]; i++)a[s[i] - '0'] ++;for(int i = 0; i <= 9; i++)if(a[i]) printf("%d:%d\n", i, a[i]);return 0;
}

L1-004. 计算摄氏温度

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈建海

给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:C = 5*(F-32)/9。题目保证输入与输出均在整型范围内。

输入格式:

输入在一行中给出一个华氏温度。

输出格式:

在一行中按照格式“Celsius = C”输出对应的摄氏温度C的整数值。

输入样例:

150

输出样例:

Celsius = 65
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;int main()
{int n;scanf("%d", &n);printf("Celsius = %d\n", (int)(5.0*(n-32)/9.0));return 0;
}

L1-005. 考试座位号

时间限制
200 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。

输入格式:

输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。

考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,以空格分隔。

输出格式:

对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。

输入样例:

4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4

输出样例:

10120150912002 2
10120150912119 1
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;int main()
{char no[1010][20], t[20];int a[1010], n, ta, tb;scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%s %d %d", t, &ta, &tb);strcpy(no[ta], t);a[ta] = tb;}scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &ta);printf("%s %d\n", no[ta], a[ta]);}return 0;
}

L1-006. 连续因子

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

一个正整数N的因子中可能存在若干连续的数字。例如630可以分解为3*5*6*7,其中5、6、7就是3个连续的数字。给定任一正整数N,要求编写程序求出最长连续因子的个数,并输出最小的连续因子序列。

输入格式:

输入在一行中给出一个正整数N(1<N<231)。

输出格式:

首先在第1行输出最长连续因子的个数;然后在第2行中按“因子1*因子2*……*因子k”的格式输出最小的连续因子序列,其中因子按递增顺序输出,1不算在内。

输入样例:

630

输出样例:

3
5*6*7
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;int main()
{int mins = 0, maxg = 0, ts = 0, tg = 0, n;scanf("%d", &n);int sq = sqrt(n);for(int i = 2; i <= sq + 1; i++){if(n % i == 0){int j = i;ts = i;tg = 0;int m = n;while(m % j == 0){m /= j;tg++;j++;}if(tg > maxg){mins = ts;maxg = tg;}}}if(maxg == 0){maxg = 1;mins = n;}printf("%d\n", maxg);printf("%d", mins);for(int i = mins + 1; i < mins + maxg; i++)printf("*%d", i);printf("\n");return 0;
}

L1-007. 念数字

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
翁恺

输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出“fu”字。十个数字对应的拼音如下:

0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu

输入格式:

输入在一行中给出一个整数,如: 1234 。

提示:整数包括负数、零和正数。

输出格式:

在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,行末没有最后的空格。如 yi er san si

输入样例:

-600

输出样例:

fu liu ling ling
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;char py[20][10] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
char s[1010];int main()
{int f = 0;scanf("%s", s);if(s[0] == '-'){printf("fu");f = 1;strcpy(s, s+1);}for(int i = 0; s[i]; i++){if(f) printf(" %s", py[s[i]-'0']);else {printf("%s", py[s[i]-'0']);f = 1;}}return 0;
}

L1-008. 求整数段和

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
杨起帆

给定两个整数A和B,输出从A到B的所有整数以及这些数的和。

输入格式:

输入在一行中给出2个整数A和B,其中-100<=A<=B<=100,其间以空格分隔。

输出格式:

首先顺序输出从A到B的所有整数,每5个数字占一行,每个数字占5个字符宽度,向右对齐。最后在一行中输出全部数字的和。

输入样例:

-3 8

输出样例:

   -3   -2   -1    0    12    3    4    5    67    8
Sum = 30

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;int main()
{int s, t, g = 0,sum = 0;scanf("%d%d", &s, &t);for(int i = s; i <= t; i++){printf("%5d", i);sum += i;g++;if(g % 5 == 0) printf("\n");}if(g % 5) printf("\n");printf("Sum = %d\n", sum);return 0;
}

L1-009. N个数求和

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

本题的要求很简单,就是求N个数字的和。麻烦的是,这些数字是以有理数“分子/分母”的形式给出的,你输出的和也必须是有理数的形式。

输入格式:

输入第一行给出一个正整数N(<=100)。随后一行按格式“a1/b1 a2/b2 ...”给出N个有理数。题目保证所有分子和分母都在长整型范围内。另外,负数的符号一定出现在分子前面。

输出格式:

输出上述数字和的最简形式 —— 即将结果写成“整数部分 分数部分”,其中分数部分写成“分子/分母”,要求分子小于分母,且它们没有公因子。如果结果的整数部分为0,则只输出分数部分。

输入样例1:

5
2/5 4/15 1/30 -2/60 8/3

输出样例1:

3 1/3

输入样例2:

2
4/3 2/3

输出样例2:

2

输入样例3:

3
1/3 -1/6 1/8

输出样例3:

7/24
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long longll gcd(ll a, ll b)
{return b == 0 ? a : ( gcd(b, a%b) );
}struct node
{ll fz, fm;friend node operator + (const node &a,const node &b){node result;result.fm = a.fm * b.fm;result.fz = a.fm * b.fz + a.fz * b.fm;result.simple();return result;}void simple(){ll gc = gcd(fz, fm);fz /= gc;fm /= gc;}void print(){if(fz == 0)printf("0\n");else if(abs(fz) < fm)printf("%lld/%lld\n", fz, fm);else if(fz % fm == 0)printf("%lld\n", fz / fm);elseprintf("%lld %lld/%lld\n", fz / fm, fz % fm, fm);}
};int main()
{int n;node ans, t;scanf("%d", &n);scanf("%lld/%lld", &ans.fz, &ans.fm);for(int i = 1; i < n; i++){scanf("%lld/%lld", &t.fz, &t.fm);ans = ans + t;}ans.print();return 0;
}

L1-010. 比较大小

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
杨起帆(浙江大学城市学院)

本题要求将输入的任意3个整数从小到大输出。

输入格式:

输入在一行中给出3个整数,其间以空格分隔。

输出格式:

在一行中将3个整数从小到大输出,其间以“->”相连。

输入样例:

4 2 8

输出样例:

2->4->8

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int a[3];scanf("%d%d%d", &a[0], &a[1], &a[2]);sort(a, a + 3);printf("%d->%d->%d\n", a[0], a[1], a[2]);return 0;
}

L1-011. A-B

时间限制
100 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

本题要求你计算A-B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A-B。

输入格式:

输入在2行中先后给出字符串A和B。两字符串的长度都不超过104,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。

输出格式:

在一行中打印出A-B的结果字符串。

输入样例:

I love GPLT!  It's a fun game!
aeiou

输出样例:

I lv GPLT!  It's  fn gm!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{char a[10100], b[10100];gets(a);gets(b);for(int i = 0; a[i]; i++){int f = 0;for(int j = 0; b[j]; j++){if(a[i] == b[j]){f = 1;break;}}if(!f) printf("%c", a[i]);}printf("\n");return 0;
}

L1-012. 计算指数

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

真的没骗你,这道才是简单题 —— 对任意给定的不超过10的正整数n,要求你输出2n。不难吧?

输入格式:

输入在一行中给出一个不超过10的正整数n。

输出格式:

在一行中按照格式“2^n = 计算结果”输出2n的值。

输入样例:

5

输出样例:

2^5 = 32
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int n, sum = 1;scanf("%d", &n);for(int i = 0; i < n; i++)sum *= 2;printf("2^%d = %d\n", n, sum);return 0;
}

L1-013. 计算阶乘和

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

对于给定的正整数N,需要你计算 S = 1! + 2! + 3! + ... + N!。

输入格式:

输入在一行中给出一个不超过10的正整数N。

输出格式:

在一行中输出S的值。

输入样例:

3

输出样例:

9
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int n, s = 0, t = 1;;scanf("%d", &n);for(int i = 1; i <= n; i++){t *= i;s += t;}printf("%d\n", s);return 0;
}

L1-014. 简单题

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

这次真的没骗你 —— 这道超级简单的题目没有任何输入。

你只需要在一行中输出事实:“This is a simple problem.”就可以了。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{printf("This is a simple problem.\n");return 0;
}

L1-015. 跟奥巴马一起画方块

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!

输入格式:

输入在一行中给出正方形边长N(3<=N<=21)和组成正方形边的某种字符C,间隔一个空格。

输出格式:

输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的50%(四舍五入取整)。

输入样例:

10 a

输出样例:

aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int n, h;char c;scanf("%d %c", &n, &c);h = (n * 5) % 10 >= 5 ? n/2 + 1 : n/2;for(int i = 0; i < h; i++){for(int j = 0; j < n; j++)printf("%c", c);printf("\n");}return 0;
}

L1-016. 查验身份证

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:

首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:

Z:0 1 2 3 4 5 6 7 8 9 10
M:1 0 X 9 8 7 6 5 4 3 2

现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。

输入格式:

输入第一行给出正整数N(<= 100)是输入的身份证号码的个数。随后N行,每行给出1个18位身份证号码。

输出格式:

按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出“All passed”。

输入样例1:

4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X

输出样例1:

12010X198901011234
110108196711301866
37070419881216001X

输入样例2:

2
320124198808240056
110108196711301862

输出样例2:

All passed
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;char m[20] = {"10X98765432"};
int q[20] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int check(char *s)
{int sum = 0;for(int i = 0; i < 17; i++){if(s[i] < '0' || s[i] > '9') return 0;sum = sum + (s[i] - '0') * q[i];}int z = sum % 11;if(m[z] != s[17]) return 0;return 1;
}int main()
{int n, sum = 0;char sf[30];scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%s", sf);if(!check(sf)){sum++;puts(sf);}}if(sum == 0) printf("All passed\n");return 0;
}

L1-017. 到底有多二

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字“-13142223336”是个11位数,其中有3个2,并且是负数,也是偶数,则它的犯二程度计算为:3/11*1.5*2*100%,约为81.82%。本题就请你计算一个给定整数到底有多二。

输入格式:

输入第一行给出一个不超过50位的整数N。

输出格式:

在一行中输出N犯二的程度,保留小数点后两位。

输入样例:

-13142223336

输出样例:

81.82%
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;int main()
{int k = 0;char a[100];gets(a);int len = strlen(a);for(int i = 0; a[i]; i++)if(a[i] == '2') k++;int j = a[len-1] - '0';if(a[0] == '-'){if(j%2 == 0) printf("%.2f%%\n", k*1.0/(len-1)*1.5*2*100);else printf("%.2f%%\n", k*1.0/(len-1)*1.5*100);}else if(j % 2 == 0) printf("%.2f%%\n", k*1.0/len*2*100);else printf("%.2f%%\n", k*1.0/len*100);return 0;
}

L1-018. 大笨钟

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。

输入格式:

输入第一行按照“hh:mm”的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。

输出格式:

根据当前时间替大笨钟敲钟,即在一行中输出相应数量个“Dang”。如果不是敲钟期,则输出:

Only hh:mm.  Too early to Dang.

其中“hh:mm”是输入的时间。

输入样例1:

19:05

输出样例1:

DangDangDangDangDangDangDangDang

输入样例2:

07:05

输出样例2:

Only 07:05.  Too early to Dang.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int h, m;scanf("%d:%d", &h, &m);if(h < 12 || h == 12 && m == 0)printf("Only %02d:%02d.  Too early to Dang.\n", h, m);else{for(int i = 13; i <= h; i++) printf("Dang");if(m > 0) printf("Dang\n");}return 0;
}

L1-019. 谁先倒

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。

下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。

输入格式:

输入第一行先后给出甲、乙两人的酒量(不超过100的非负整数),以空格分隔。下一行给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式为:

甲喊 甲划 乙喊 乙划

其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只手一起划)。

输出格式:

在第一行中输出先倒下的那个人:A代表甲,B代表乙。第二行中输出没倒的那个人喝了多少杯。题目保证有一个人倒下。注意程序处理到有人倒下就终止,后面的数据不必处理。

输入样例:

1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16

输出样例:

A
1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;int main()
{int A, B, n, AA, BB;int a, b, c, d, f = 0;scanf("%d%d%d", &A, &B, &n);AA = A;BB = B;for(int i = 0; i < n; i++){scanf("%d%d%d%d", &a, &b, &c, &d);if(f) continue;int ta, tb;ta = tb = 0;if(b == a + c) ta = 1;if(d == a + c) tb = 1;if(ta && !tb) A--;if(tb && !ta) B--;if(A < 0) f = 1;if(B < 0) f = 2;}if(f == 1) printf("A\n%d\n", BB-B);if(f == 2) printf("B\n%d\n", AA-A);return 0;
}

L1-020. 帅到没朋友

时间限制
200 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友。本题就要求你找出那些帅到没有朋友的人。

输入格式:

输入第一行给出一个正整数N(<=100),是已知朋友圈的个数;随后N行,每行首先给出一个正整数K(<=1000),为朋友圈中的人数,然后列出一个朋友圈内的所有人——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为待查询的人数;随后一行中列出M个待查询的ID,以空格分隔。

注意:没有朋友的人可以是根本没安装“朋友圈”,也可以是只有自己一个人在朋友圈的人。虽然有个别自恋狂会自己把自己反复加进朋友圈,但题目保证所有K超过1的朋友圈里都至少有2个不同的人。

输出格式:

按输入的顺序输出那些帅到没朋友的人。ID间用1个空格分隔,行的首尾不得有多余空格。如果没有人太帅,则输出“No one is handsome”。

注意:同一个人可以被查询多次,但只输出一次。

输入样例1:

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888

输出样例1:

10000 88888 23333

输入样例2:

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111

输出样例2:

No one is handsome
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int n, k, t, f = 0;map<int, int> M;scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &k);for(int j = 0; j < k; j++){scanf("%d", &t);if(k == 1) continue;M[t]++;}}scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &t);if(M[t] == 0){M[t] = 1;if(!f) {printf("%05d", t); f = 1;}else printf(" %05d", t);}}if(!f) printf("No one is handsome");printf("\n");return 0;
}

L1-021. 重要的话说三遍

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— “I'm gonna WIN!”——连续输出三遍就可以了。

注意每遍占一行,除了每行的回车不能有任何多余字符。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{printf("I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!\n");return 0;
}

L1-022. 奇偶分家

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

给定N个正整数,请统计奇数和偶数各有多少个?

输入格式:

输入第一行给出一个正整N(<= 1000);第2行给出N个正整数,以空格分隔。

输出格式:

在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。

输入样例:

9
88 74 101 26 15 0 34 22 77

输出样例:

3 6

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int j = 0, o = 0, n, t;scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &t);if(t % 2 == 0) o ++;else j ++;}printf("%d %d\n", j, o);return 0;
}

L1-023. 输出GPLT

时间限制
150 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按“GPLTGPLT....”这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。

输入格式:

输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。

输出格式:

在一行中按题目要求输出排序后的字符串。题目保证输出非空。

输入样例:

pcTclnGloRgLrtLhgljkLhGFauPewSKgt

输出样例:

GPLTGPLTGLTGLGLL

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int g, p, l, t;char s[10100];g = p = l = t = 0;gets(s);for(int i = 0; s[i]; i++)if(s[i] == 'g' || s[i] == 'G') g++;else if(s[i] == 'p' || s[i] == 'P') p++;else if(s[i] == 'l' || s[i] == 'L') l++;else if(s[i] == 't' || s[i] == 'T') t++;while(g != 0 || p != 0 || l != 0 || t != 0){if(g){printf("G");g--;}if(p){printf("P");p--;}if(l){printf("L");l--;}if(t){printf("T");t--;}}printf("\n");return 0;
}

L1-024. 后天

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几。

输入格式:

输入第一行给出一个正整数D(1 <= D <=7),代表星期里的某一天。

输出格式:

在一行中输出D天的后天是星期几。

输入样例:

3

输出样例:

5
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int n;scanf("%d", &n);n--;printf("%d\n", (n + 2) % 7 + 1);return 0;
}

L1-025. 正整数A+B

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000]。稍微有点麻烦的是,输入并不保证是两个正整数。

输入格式:

输入在一行给出A和B,其间以空格分开。问题是A和B不一定是满足要求的正整数,有时候可能是超出范围的数字、负数、带小数点的实数、甚至是一堆乱码。

注意:我们把输入中出现的第1个空格认为是A和B的分隔。题目保证至少存在一个空格,并且B不是一个空字符串。

输出格式:

如果输入的确是两个正整数,则按格式“A + B = 和”输出。如果某个输入不合要求,则在相应位置输出“?”,显然此时和也是“?”。

输入样例1:

123 456

输出样例1:

123 + 456 = 579

输入样例2:

22. 18

输出样例2:

? + 18 = ?

输入样例3:

-100 blabla bla...33

输出样例3:

? + ? = ?
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int fa = 0, fb = 0, ia = 0, ib = 0, k, cb = 0;char a[101000], b[101000];scanf("%s ",a);gets(b);for(int i = 0; a[i]; i++){if(a[i] < '0' || a[i] > '9') fa = 1;if(fa) break;ia = ia * 10 + a[i] - '0';}for(int i = 0; b[i]; i++){if(b[i] < '0' || b[i] > '9') fb = 1;if(fb) break;ib = ib * 10 + b[i] - '0';}if(ia < 1 || ia > 1000) fa = 1;if(ib < 1 || ib > 1000) fb = 1;if(fa && fb) printf("? + ? = ?\n");else if(fa) printf("? + %s = ?\n", b);else if(fb) printf("%s + ? = ?\n", a);else printf("%s + %s = %d\n", a, b, ia + ib);return 0;
}

L1-026. I Love GPLT

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— “I Love GPLT”——竖着输出就可以了。

所谓“竖着输出”,是指每个字符占一行(包括空格),即每行只能有1个字符和回车。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{printf("I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n");return 0;
}

L1-027. 出租

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

下面是新浪微博上曾经很火的一张图:

一时间网上一片求救声,急问这个怎么破。其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对应 arr[0]=8,index[2]=3 对应 arr[3]=0,以此类推…… 很容易得到电话号码是18013820100。

本题要求你编写一个程序,为任何一个电话号码生成这段代码 —— 事实上,只要生成最前面两行就可以了,后面内容是不变的。

输入格式:

输入在一行中给出一个由11位数字组成的手机号码。

输出格式:

为输入的号码生成代码的前两行,其中arr中的数字必须按递减顺序给出。

输入样例:

18013820100

输出样例:

int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;int main()
{int arr[20], a[10] = {0}, t = 0, f = 0;char str[20];scanf("%s", str);for(int i = 0; str[i]; i++)a[str[i] - '0'] ++;for(int i = 0; i < 10; i++)if(a[i]) arr[t++] = i;sort(arr, arr + t, greater<int>());printf("int[] arr = new int[]{");printf("%d", arr[0]);for(int i = 1; i < t; i++)printf(",%d", arr[i]);printf("};\nint[] index = new int[]{");for(int i = 0; str[i]; i++){for(int j = 0; j < t; j++){if(str[i] - '0' == arr[j]){if(!f) {f = 1; printf("%d", j);}else printf(",%d", j);}}}printf("};\n");return 0;
}

L1-028. 判断素数

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

本题的目标很简单,就是判断一个给定的正整数是否素数。

输入格式:

输入在第一行给出一个正整数N(<=10),随后N行,每行给出一个小于231的需要判断的正整数。

输出格式:

对每个需要判断的正整数,如果它是素数,则在一行中输出“Yes”,否则输出“No”。

输入样例:

2
11
111

输出样例:

Yes
No

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;int pd(int s)
{if(s == 0 || s == 1) return 0;if(s == 2) return 1;int len = sqrt(s);for(int i = 2; i <= len; i++)if(s % i == 0) return 0;return 1;
}int main()
{int n, t;scanf("%d", &n);while(n--){scanf("%d", &t);if(pd(t)) printf("Yes\n");else printf("No\n");}return 0;
}

L1-029. 是不是太胖了

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。已知市斤是公斤的两倍。现给定某人身高,请你计算其标准体重应该是多少?(顺便也悄悄给自己算一下吧……)

输入格式:

输入第一行给出一个正整数H(100 < H <= 300),为某人身高。

输出格式:

在一行中输出对应的标准体重,单位为市斤,保留小数点后1位。

输入样例:

169

输出样例:

124.2

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;int main()
{int h;scanf("%d", &h);printf("%.1lf\n", (h - 100) * 0.9 * 2);return 0;
}

L1-030. 一帮一

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的异性学生分为一组。

输入格式:

输入第一行给出正偶数N(<=50),即全班学生的人数。此后N行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名次。

输出格式:

每行输出一组两个学生的姓名,其间以1个空格分隔。名次高的学生在前,名次低的学生在后。小组的输出顺序按照前面学生的名次从高到低排列。

输入样例:

8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda

输出样例:

Amy Jack
Tom Linda
Bill Maya
Cindy John

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;struct node
{char name[10];int sex;
}w[100];int vis[100];int main()
{int n, t;scanf("%d", &n);for(int i = 0; i < n; i++)scanf("%d %s", &w[i].sex, w[i].name);for(int i = 0; i < n / 2; i++){for(int t = n - 1; t >= 0; t--){if(w[t].sex != w[i].sex && !vis[t]){printf("%s %s\n", w[i].name, w[t].name);vis[t] = 1;break;}}}return 0;
}

L1-031. 到底是不是太胖了

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。真实体重与标准体重误差在10%以内都是完美身材(即 |真实体重-标准体重| < 标准体重x10%)。已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。

输入格式:

输入第一行给出一个正整数N(<= 20)。随后N行,每行给出两个整数,分别是一个人的身高H(120 < H < 200;单位:厘米)和真实体重W(50 < W <= 300;单位:市斤),其间以空格分隔。

输出格式:

为每个人输出一行结论:如果是完美身材,输出“You are wan mei!”;如果太胖了,输出“You are tai pang le!”;否则输出“You are tai shou le!”。

输入样例:

3
169 136
150 81
178 155

输出样例:

You are wan mei!
You are tai shou le!
You are tai pang le!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;int main()
{int cas;scanf("%d", &cas);while(cas--){int a,b;scanf("%d %d", &a, &b);double ss = 0.9*(a-100)*2;double sj = b-ss;if( fabs(sj) < ss*0.1-1e-9 )printf("You are wan mei!\n");else if(  sj >= ss*0.1 )printf("You are tai pang le!\n");elseprintf("You are tai shou le!\n");}return 0;
}

L1-032. Left-pad

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

根据新浪微博上的消息,有一位开发者不满NPM(Node Package Manager)的做法,收回了自己的开源代码,其中包括一个叫left-pad的模块,就是这个模块把javascript里面的React/Babel干瘫痪了。这是个什么样的模块?就是在字符串前填充一些东西到一定的长度。例如用“*”去填充字符串“GPLT”,使之长度为10,调用left-pad的结果就应该是“******GPLT”。Node社区曾经对left-pad紧急发布了一个替代,被严重吐槽。下面就请你来实现一下这个模块。

输入格式:

输入在第一行给出一个正整数N(<=104)和一个字符,分别是填充结果字符串的长度和用于填充的字符,中间以1个空格分开。第二行给出原始的非空字符串,以回车结束。

输出格式:

在一行中输出结果字符串。

输入样例1:

15 _
I love GPLT

输出样例1:

____I love GPLT

输入样例2:

4 *
this is a sample for cut

输出样例2:

 cut
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;char s[1010000], c;int main()
{int n;scanf("%d %c", &n, &c);getchar();gets(s);int len = strlen(s);if(len >= n){int x = len - n;printf("%s\n", s+x);}else{int x = n - len;for(int i = 0; i < x; i++)printf("%c", c);printf("%s\n", s);}return 0;
}

团体程序设计天梯赛-练习集 L1阶段 全部题解相关推荐

  1. 团体程序设计天梯赛-练习集 L2 阶段全部题解

    L2-001. 紧急救援 地址链接:https://blog.csdn.net/dengkuomin/article/details/64498691 L2-002. 链表去重 地址链接:https: ...

  2. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L1 答案

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L1 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 标号 标题 分数 通过数 提交数 通过率 L1-001 Hello World 5 46779 1 ...

  3. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L2 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 知识点分类(32): 1.树锯结构(9):二叉树的存储,编号,遍历顺序转换,求深度,底层节点,从底 ...

  4. 团体程序设计天梯赛 -- 练习集 (L1合集)

    文章目录 L1-001 Hello World (5 分) L1-002 打印沙漏 (20 分) L1-003 个位数统计 (15 分) L1-004 计算摄氏温度 (5 分) L1-005 考试座位 ...

  5. PAT : 团体程序设计天梯赛-练习集L1 个人题解

    另把天梯赛所有题解内容全部打包成了一个文档,可以自行下载:https://download.csdn.net/download/daixinliangwyx/11170075 L1-001 Hello ...

  6. 团体程序设计天梯赛-练习集 L1

    目录 L1-001 Hello World L1-002 打印沙漏 L1-003 个位数统计 L1-004 计算摄氏温度 L1-005 考试座位号 L1-006 连续因子[枚举] L1-007 念数字 ...

  7. 团体程序设计天梯赛-练习集 L1合集

    来自<https://www.patest.cn/contests/gplt> L1-001. Hello World 这道超级简单的题目没有任何输入. 你只需要在一行中输出著名短句&qu ...

  8. 团体程序设计天梯赛-练习集-L1区001——048C语言全解

    题目链接:https://www.patest.cn/contests/gplt 所有一区的题都是用c语言编写的,都通过了,有的可能设计的比较复杂.仅供参考,同时也感谢网上的一些大佬们提供的思路.如果 ...

  9. 团体程序设计天梯赛练习集题解整合

    网上介绍 团体程序设计天梯赛练习集 的文章已经很多了, 我的这篇文章是对练习集题解的整合,方便每一位备战 团体程序设计天梯赛 的同学使用. 一年一度的 团体程序设计天梯赛 即将开始,PTA的练习集是必 ...

最新文章

  1. linux下的ping脚本,Linux下检测服务器Ping值的Shell脚本
  2. [异常解决] How make ubuntu use Google Search
  3. Java基础:基本数据类型包装类
  4. 为什么D触发器需要建立时间与保持时间
  5. Jakarta EE中的规范范围
  6. 面试:Websocket
  7. C# 中 NPOI 库读写 Excel 文件的方法【摘】
  8. phpstudy配置oracle,phpStudy配置sql、oracle---博主摘录
  9. 非递归求解N皇后问题(回溯法)
  10. 关于ASP.NET 将数据导出成Excel 的总结[下]
  11. 中国移动MM,你需要了解
  12. Nginx从入门到入坟(十)- Rewrite功能详解与案例实操
  13. 《部落冲突:皇室战争》——一款不能错过的游戏!
  14. uni-app实现仿微信前端(二)
  15. python_qzonespider_day2_模拟登录QQ空间
  16. html搜索栏热搜效果,CSS3实战开发:百度新闻热搜词特效实战开发_html/css_WEB-ITnose...
  17. 全国大学生智能汽车竞赛
  18. 阿里P10、腾讯T4、华为18,互联网公司职级、薪资、股权大揭秘
  19. 借助人脸识别智能门禁,管好智慧工地出入口
  20. Siamese Network (应用篇3) :孪生网络用于图像块匹配 ACCV2016

热门文章

  1. RTX 3080被炒到原价7倍,最高卖5000美元,英伟达官方道歉:将打击黄牛抢购
  2. 获取微信QQ好友高精地址
  3. Keil uVision5 界面模糊(优化)变清晰
  4. 整数拆分为连续自然数之和
  5. 室内模拟高尔夫成潮流新贵,挥杆篙尔夫体现娱乐体验价值
  6. 中国式SaaS技术架构
  7. 网络营销技巧:有必要为移动端专门做站吗?
  8. 电力系统的延时功率流 (CPF)的计算【 IEEE-14节点】(Matlab代码实现)
  9. 遇见CSDN蒋总和众多大咖
  10. 改成每天晚上锻炼身体