来自<https://www.patest.cn/contests/gplt>

L1-001. Hello World

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

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

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int main(){cout<<"Hello World!"<<endl;
}

L1-002. 打印沙漏

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

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

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

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

输入格式:

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

输出格式:

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

输入样例:

19 *

输出样例:

************
*****
2
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int main(){int n;string s;cin>>n>>s;int m=1,i=3;for(;;i+=2){if(m+i*2>n) break;m+=i*2;}i-=2;for(int j=0;j<=i/2;j++){for(int k=0;k<j;k++)cout<<" ";for(int k=0;k<i-j*2;k++)cout<<s;cout<<endl;}for(int j=i/2-1;j>=0;j--){for(int k=0;k<j;k++)cout<<" ";for(int k=0;k<i-j*2;k++)cout<<s;cout<<endl;}cout<<n-m<<endl;
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int a[11];
int main(){string s;cin>>s;int len=s.length();for(int i=0;i<len;i++){a[s[i]-'0']++;}for(int i=0;i<=9;i++){if(a[i]) printf("%d:%d\n",i,a[i]);}
}

L1-004. 计算摄氏温度

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈建海

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

输入格式:

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

输出格式:

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

输入样例:

150

输出样例:

Celsius = 65
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int a[11];
int main(){int n;cin>>n;n=(n-32)*5/9;cout<<"Celsius = "<<n<<endl;
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
struct Node{string a,b,c;
}a[10005];
int main(){int n;cin>>n;string x,y,z;for(int i=1;i<=n;i++){cin>>x>>y>>z;a[i].a=x;a[i].b=y;a[i].c=z;}int m;cin>>m;for(int i=1;i<=m;i++){cin>>x;for(int j=1;j<=n;j++){if(a[j].b==x) cout<<a[j].a<<" "<<a[j].c<<endl;}}
}

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
//2^31为2147483648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){LL n,m,ans,tmp,cnt=0,cntp=0;scanf("%lld",&n);m=LL(sqrt(n))+1;for(LL i=2;i<=m;i++){if(n%i==0){tmp=i;cntp=1;for(LL j=i+1;j<=m;j++){tmp*=j;if(n%tmp!=0)break;cntp++;}if(cntp>cnt) cnt=cntp,ans=i;}}if(cnt==0){printf("1\n%lld\n",n);}else{printf("%lld\n",cnt);for(LL i=ans;i<ans+cnt-1;i++){printf("%lld*",i);}printf("%lld\n",ans+cnt-1);}
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};string fu="fu";string a;cin>>a;int len=a.length();for(int i=0;i<len;i++){if(a[i]=='-') cout<<fu;else cout<<s[a[i]-'0'];if(i!=len-1) cout<<" ";else cout<<endl;}
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a,b,sum=0;cin>>a>>b;for(int i=a;i<=b;i++){if((i-a)%5==0&&i>a) cout<<endl;printf("%5d",i);sum+=i;}printf("\nSum = %d",sum);
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
LL lcm(LL a,LL b){return a/__gcd(a,b)*b;
}
int main(){LL n,fm=1;LL a[105][2];string s;cin>>n;for(LL i=1;i<=n;i++){cin>>s;LL x=0,len=s.length(),flag=1,j;for(j=0;j<len;j++){if(s[j]=='-') flag=0;else if(s[j]=='/') break;else x=x*10+s[j]-'0';}if(flag==0) x=-x;a[i][0]=x;if(j==len){a[i][1]=1;continue;}flag=1,x=0;for(j++;j<len;j++)x=x*10+s[j]-'0';if(flag==0) x=-x;a[i][1]=x;fm=lcm(x,fm);}LL fz=0;for(LL i=1;i<=n;i++)fz+=fm/a[i][1]*a[i][0];LL ans1=fz/fm,ans2=abs(fz)%fm;LL t=__gcd(ans2,fm);ans2/=t;fm/=t;if(ans1) cout<<ans1;else if(!ans2) cout<<ans1;if(ans2){if(ans1) cout<<" ";else if(fz<0) ans2=-ans2;cout<<ans2<<"/"<<fm;}cout<<endl;
}

L1-010. 比较大小

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

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

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

输入格式:

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

输出格式:

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

输入样例:

4 2 8

输出样例:

2->4->8
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a[3];cin>>a[0]>>a[1]>>a[2];sort(a,a+3);cout<<a[0]<<"->"<<a[1]<<"->"<<a[2]<<endl;
}

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!
//B字符串可能有空格
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){char c[100005],s[100005];gets(c);gets(s);int a[500];for(int i=0;i<500;i++) a[i]=1;int len=strlen(s);for(int i=0;i<len;i++) a[s[i]]=0;len=strlen(c);for(int i=0;i<len;i++){if(a[c[i]]) cout<<c[i];}cout<<endl;
}

L1-012. 计算指数

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

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

输入样例:

5

输出样例:

2^5 = 32
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n;LL ans=1;cin>>n;for(int i=1;i<=n;i++) ans*=2;cout<<"2^"<<n<<" = "<<ans<<endl;
}

L1-013. 计算阶乘和

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

在一行中输出S的值。

输入样例:

3

输出样例:

9
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){LL ans=0,n;cin>>n;LL tmp=1;for(int i=1;i<=n;i++){tmp*=i;ans+=tmp;}cout<<ans;
}

L1-014. 简单题

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

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

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){
    cout<<"This is a simple problem."<<endl;

}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n,m;string s;cin>>n>>s;m=int(floor(1.0*n/2+0.5));for(int i=1;i<=m;i++){for(int j=1;j<=n;j++)cout<<s;cout<<endl;}
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int v[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};char m[]="10X98765432";int n;cin>>n;string s;vector<string>ans;for(int i=1;i<=n;i++){cin>>s;int sum=0;for(int j=0;j<17;j++){int x=0;if(s[j]=='X') x=10;else x=s[j]-'0';sum+=x*v[j];}sum=sum%11;if(m[sum]!=s[17]) ans.push_back(s);}if(ans.size())for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;else cout<<"All passed"<<endl;
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s;cin>>s;int len=s.length();int i=0;double fu=1,fd=1;if(s[0]=='-') i++,fu=1.5;double ans=0;for(;i<len;i++)if(s[i]=='2') ans++;if((s[len-1]-'0')%2==0) fd=2;ans=ans/len*fu*fd*100;printf("%.2f%%\n",ans);
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s;cin>>s;int h=s[1]-'0'+(s[0]-'0')*10;int f=s[4]-'0'+(s[3]-'0')*10;if(f) h++;if(h<=12) cout<<"Only "<<s<<".  Too early to Dang."<<endl;else{h-=12;for(int i=1;i<=h;i++)cout<<"Dang";cout<<endl;}
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a,b;cin>>a>>b;int n;int a1,a2,b1,b2;int cnta=0,cntb=0;int ans1=0,ans2;cin>>n;while(n--){cin>>a1>>a2>>b1>>b2;if(!ans1){if(a1+b1==a2&&a1+b1!=b2) cnta++;else if(a1+b1!=a2&&a1+b1==b2) cntb++;if(cnta>a) ans1=1,ans2=cntb;else if(cntb>b) ans1=2,ans2=cnta;}}cout<<char(ans1+'A'-1)<<endl;cout<<ans2<<endl;
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int a[100005];
int main(){int n,m,x;cin>>n;while(n--){cin>>m;for(int i=1;i<=m;i++){cin>>x;if(m>1) a[x]=1;}}cin>>m;int first=1;while(m--){cin>>x;if(!a[x]){if(first) first=0;else cout<<" ";printf("%05d",x);a[x]=1;}}if(first) cout<<"No one is handsome";cout<<endl;
}

L1-021. 重要的话说三遍

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

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

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

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int a[100005];
int main(){
    cout<<"I'm gonna WIN!"<<endl;
    cout<<"I'm gonna WIN!"<<endl;
    cout<<"I'm gonna WIN!"<<endl;

}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n,x,ans1=0,ans2=0;cin>>n;while(n--){cin>>x;if(x%2) ans1++;else ans2++;}cout<<ans1<<" "<<ans2<<endl;
}

L1-023. 输出GPLT

时间限制
150 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

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

输入样例:

pcTclnGloRgLrtLhgljkLhGFauPewSKgt

输出样例:

GPLTGPLTGLTGLGLL
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s;cin>>s;int len=s.length();int g=0,p=0,l=0,t=0;for(int i=0;i<len;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||p||l||t){if(g) cout<<'G',g--;if(p) cout<<'P',p--;if(l) cout<<'L',l--;if(t) cout<<'T',t--;}cout<<endl;
}

L1-024. 后天

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

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

输入样例:

3

输出样例:

5

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){
    int n;
    cin>>n;
    n+=2;if(n>7) n-=7;
    cout<<n<<endl;

}

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:

? + ? = ?
//a和b都以第一个空格分隔,多出的空格属于字符串b
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string a,b,c="";cin>>a>>b;while(cin>>c);int aa=0,bb=0;int la=a.length(),lb=b.length();for(int i=0;i<la;i++){if(a[i]>'9'||a[i]<'0'){aa=-1;break;}aa=aa*10+a[i]-'0';}for(int i=0;i<lb;i++){if(b[i]>'9'||b[i]<'0'){bb=-1;break;}bb=bb*10+b[i]-'0';}if(c!="") bb=-1;if(aa>=1&&aa<=1000) cout<<aa;else cout<<'?';cout<<" + ";if(bb>=1&&bb<=1000) cout<<bb;else cout<<'?';cout<<" = ";if(aa>=1&&aa<=1000&&bb>=1&&bb<=1000) cout<<aa+bb<<endl;else cout<<'?'<<endl;
}

L1-026. I Love GPLT

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

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

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

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string a="I Love GPLT";int n=a.length();for(int i=0;i<n;i++) cout<<a[i]<<endl;
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int vis[15];
int main(){string s;cin>>s;int len=s.length();for(int i=0;i<len;i++){vis[s[i]-'0']++;}int a[15],cnt=0;printf("int[] arr = new int[]{");for(int i=9;i>=0;i--)if(vis[i]){a[i]=cnt++;if(cnt!=1) printf(",");printf("%d",i);}printf("};\n");printf("int[] index = new int[]{");for(int i=0;i<len;i++){if(i!=0) printf(",");printf("%d",a[s[i]-'0']);}printf("};\n");
}

L1-028. 判断素数

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

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

输入样例:

2
11
111

输出样例:

Yes
No
//for(i=2;i*i<=x;i++)这样写会TLE
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n,x;scanf("%d",&n);while(n--){scanf("%d",&x);if(x==1) puts("No");else{int i;for(i=2;i<=sqrt(x);i++){if(x%i==0){puts("No");break;}}if(i>sqrt(x)) puts("Yes");}}
}

L1-029. 是不是太胖了

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

输入格式:

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

输出格式:

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

输入样例:

169

输出样例:

124.2
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){double a;cin>>a;a-=100;a*=1.8;printf("%.1f\n",a);
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n;string s[60],girl[60],boy[60];int a[60];int ng=0,nb=0;cin>>n;for(int i=1;i<=n;i++){cin>>a[i]>>s[i];if(a[i]) girl[++ng]=s[i];else boy[++nb]=s[i];}for(int i=1;i<=n/2;i++){if(a[i]==1) cout<<s[i]<<" "<<boy[nb--]<<endl;else cout<<s[i]<<" "<<girl[ng--]<<endl;}
}

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
char s[1000005];
int main(){int n;string x;cin>>n>>x;getchar();gets(s);int m=strlen(s);if(m>n)for(int i=m-n;i<m;i++)cout<<s[i];else{for(int i=1;i<=n-m;i++)cout<<x;cout<<s;}cout<<endl;
}

L1-033. 出生年

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

以上是新浪微博中一奇葩贴:“我出生于1988年,直到25岁才遇到4个数字都不相同的年份。”也就是说,直到2013年才达到“4个数字都不相同”的要求。本题请你根据要求,自动填充“我出生于y年,直到x岁才遇到n个数字都不相同的年份”这句话。

输入格式:

输入在一行中给出出生年份y和目标年份中不同数字的个数n,其中y在[1, 3000]之间,n可以是2、或3、或4。注意不足4位的年份要在前面补零,例如公元1年被认为是0001年,有2个不同的数字0和1。

输出格式:

根据输入,输出x和能达到要求的年份。数字间以1个空格分隔,行首尾不得有多余空格。年份要按4位输出。注意:所谓“n个数字都不相同”是指不同的数字正好是n个。如“2013”被视为满足“4位数字都不同”的条件,但不被视为满足2位或3位数字不同的条件。

输入样例1:

1988 4

输出样例1:

25 2013

输入样例2:

1 2

输出样例2:

0 0001
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n,m,vis[20];cin>>n>>m;int nn=n;while(1){memset(vis,0,sizeof(vis));int a=nn/1000,b=(nn-a*1000)/100,c=(nn/10)%10,d=nn%10;vis[a]=1,vis[b]=1,vis[c]=1,vis[d]=1;int cnt=0;for(int i=0;i<=9;i++) cnt+=vis[i];if(cnt==m){printf("%d %04d",nn-n,nn);break;}nn++;}
}

L1-034. 点赞

时间限制
200 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。本题就要求你写个程序,通过统计一个人点赞的纪录,分析这个人的特性。

输入格式:

输入在第一行给出一个正整数N(<=1000),是该用户点赞的博文数量。随后N行,每行给出一篇被其点赞的博文的特性描述,格式为“K F1... FK”,其中 1<=K<=10,Fi(i=1, ..., K)是特性标签的编号,我们将所有特性标签从1到1000编号。数字间以空格分隔。

输出格式:

统计所有被点赞的博文中最常出现的那个特性标签,在一行中输出它的编号和出现次数,数字间隔1个空格。如果有并列,则输出编号最大的那个。

输入样例:

4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123

输出样例:

233 3
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int a[10005];
int main(){int n,m,x,ans=-1,anst=-1;cin>>n;while(n--){cin>>m;while(m--){cin>>x;a[x]++;if(a[x]>anst||(a[x]==anst&&x>ans))anst=a[x],ans=x;}}cout<<ans<<" "<<anst<<endl;
}

L1-035. 情人节

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

以上是朋友圈中一奇葩贴:“2月14情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋。

输入格式:

输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空单词,以回车结束。一个英文句点“.”标志输入的结束,这个符号不算在点赞名单里。

输出格式:

根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner...”;若只有A没有B,则输出“A is the only one for you...”;若连A都没有,则输出“Momo... No one is for you ...”。

输入样例1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

输出样例1:

Magi and Potaty are inviting you to dinner...

输入样例2:

LaoLao
FatMouse
whoever
.

输出样例2:

FatMouse is the only one for you...

输入样例3:

LaoLao
.

输出样例3:

Momo... No one is for you ...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s,a,b;int cnt=0;while(cin>>s){if(s==".") break;cnt++;if(cnt==2) a=s;else if(cnt==14) b=s;if(cnt>15) cnt=15;}if(cnt<2) cout<<"Momo... No one is for you ..."<<endl;else if(cnt>=14) cout<<a<<" and "<<b<<" are inviting you to dinner..."<<endl;else cout<<a<<" is the only one for you..."<<endl;
}

L1-036. A乘以B

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

看我没骗你吧 —— 这是一道你可以在10秒内完成的题:给定两个绝对值不超过100的整数A和B,输出A乘以B的值。

输入格式:

输入在第一行给出两个整数A和B(-100 <= A, B, <= 100),数字间以空格分隔。

输出格式:

在一行中输出A乘以B的值。

输入样例:

-8 13

输出样例:

-104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a,b;cin>>a>>b;cout<<a*b<<endl;
}

L1-037. A除以B

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

真的是简单题哈 —— 给定两个绝对值不超过100的整数A和B,要求你按照“A/B=商”的格式输出结果。

输入格式:

输入在第一行给出两个整数A和B(-100 <= A, B, <= 100),数字间以空格分隔。

输出格式:

在一行中输出结果:如果分母是正数,则输出“A/B=商”;如果分母是负数,则要用括号把分母括起来输出;如果分母为零,则输出的商应为“Error”。输出的商应保留小数点后2位。

输入样例1:

-1 2

输出样例1:

-1/2=-0.50

输入样例2:

1 -3

输出样例2:

1/(-3)=-0.33

输入样例3:

5 0

输出样例3:

5/0=Error
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a,b;cin>>a>>b;if(b==0) printf("%d/0=Error\n",a);else if(b<0) printf("%d/(%d)=%.2f\n",a,b,1.0*a/b);else printf("%d/%d=%.2f\n",a,b,1.0*a/b);
}

L1-038. 新世界

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

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

你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){cout<<"Hello World"<<endl;cout<<"Hello New World"<<endl;
}

L1-039. 古风排版

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。

输入格式:

输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。

输出格式:

按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)

输入样例:

4
This is a test case

输出样例:

asa T
st ih
e tsice s
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n;char s[1005];cin>>n;getchar();gets(s);int len=strlen(s);for(int i=0;i<=n;i++) s[len+i]=' ';int c=len/n+(len%n!=0);char ans[105][105];int now=0;for(int j=c;j>=1;j--)for(int i=1;i<=n;i++)ans[i][j]=s[now++];for(int i=1;i<=n;i++){for(int j=1;j<=c;j++)cout<<ans[i][j];cout<<endl;}}

L1-040. 最佳情侣身高差

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

专家通过多组情侣研究数据发现,最佳的情侣身高差遵循着一个公式:(女方的身高)×1.09=(男方的身高)。如果符合,你俩的身高差不管是牵手、拥抱、接吻,都是最和谐的差度。

下面就请你写个程序,为任意一位用户计算他/她的情侣的最佳身高。

输入格式:

输入第一行给出正整数N(<=10),为前来查询的用户数。随后N行,每行按照“性别 身高”的格式给出前来查询的用户的性别和身高,其中“性别”为“F”表示女性、“M”表示男性;“身高”为区间 [1.0, 3.0] 之间的实数。

输出格式:

对每一个查询,在一行中为该用户计算出其情侣的最佳身高,保留小数点后2位。

输入样例:

2
M 1.75
F 1.8

输出样例:

1.61
1.96
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n;string s;double x;cin>>n;while(n--){cin>>s>>x;if(s=="F") printf("%.2f\n",x*1.09);else printf("%.2f\n",x/1.09);}
}

L1-041. 寻找250

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

对方不想和你说话,并向你扔了一串数…… 而你必须从这一串数字中找到“250”这个高大上的感人数字。

输入格式:

输入在一行中给出不知道多少个绝对值不超过1000的整数,其中保证至少存在一个“250”。

输出格式:

在一行中输出第一次出现的“250”是对方扔过来的第几个数字(计数从1开始)。题目保证输出的数字在整型范围内。

输入样例:

888 666 123 -233 250 13 250 -222

输出样例:

5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int x,ans=-1,cnt=0;while(cin>>x){cnt++;if(ans==-1&&x==250)ans=cnt;}cout<<ans<<endl;
}

L1-042. 日期格式化

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

世界上不同国家有不同的写日期的习惯。比如美国人习惯写成“月-日-年”,而中国人习惯写成“年-月-日”。下面请你写个程序,自动把读入的美国格式的日期改写成中国习惯的日期。

输入格式:

输入在一行中按照“mm-dd-yyyy”的格式给出月、日、年。题目保证给出的日期是1900年元旦至今合法的日期。

输出格式:

在一行中按照“yyyy-mm-dd”的格式给出年、月、日。

输入样例:

03-15-2017

输出样例:

2017-03-15
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s;cin>>s;cout<<s[6]<<s[7]<<s[8]<<s[9]<<'-'<<s[0]<<s[1]<<'-'<<s[3]<<s[4]<<endl;
}

L1-043. 阅览室

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下S键,程序开始计时;当读者还书时,管理员输入书号并按下E键,程序结束计时。书号为不超过1000的正整数。当管理员将0作为书号输入时,表示一天工作结束,你的程序应输出当天的读者借书次数和平均阅读时间。

注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有S没有E,或者只有E没有S的纪录,系统应能自动忽略这种无效纪录。另外,题目保证书号是书的唯一标识,同一本书在任何时间区间内只可能被一位读者借阅。

输入格式:

输入在第一行给出一个正整数N(<= 10),随后给出N天的纪录。每天的纪录由若干次借阅操作组成,每次操作占一行,格式为:

书号([1, 1000]内的整数) 键值(“S”或“E”) 发生时间(hh:mm,其中hh是[0,23]内的整数,mm是[0, 59]内整数)

每一天的纪录保证按时间递增的顺序给出。

输出格式:

对每天的纪录,在一行中输出当天的读者借书次数和平均阅读时间(以分钟为单位的精确到个位的整数时间)。

输入样例:

3
1 S 08:10
2 S 08:35
1 E 10:00
2 E 13:16
0 S 17:00
0 S 17:00
3 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20
0 E 17:00

输出样例:

2 196
0 0
1 60
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int a[1005],n,k,t,av,cnt;int ans[15][2],num=0;string x,s;cin>>n;while(n--){cnt=0,av=0;memset(a,-1,sizeof(a));while(cin>>k>>x>>s){if(k==0) break;int t=(s[1]-'0'+(s[0]-'0')*10)*60+s[4]-'0'+10*(s[3]-'0');if(a[k]>=0&&x=="E")av+=t-a[k],cnt++,a[k]=-1;else a[k]=t;}ans[++num][0]=cnt,ans[num][1]=cnt?int(floor(1.0*av/cnt+0.5)):0;}for(int i=1;i<=num;i++)cout<<ans[i][0]<<" "<<ans[i][1]<<endl;
}

L1-044. 稳赢

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

现要求你编写一个稳赢不输的程序,根据对方的出招,给出对应的赢招。但是!为了不让对方输得太惨,你需要每隔K次就让一个平局。

输入格式:

输入首先在第一行给出正整数K(<=10),即平局间隔的次数。随后每行给出对方的一次出招:“ChuiZi”代表“锤子”、“JianDao”代表“剪刀”、“Bu”代表“布”。“End”代表输入结束,这一行不要作为出招处理。

输出格式:

对每一个输入的出招,按要求输出稳赢或平局的招式。每招占一行。

输入样例:

2
ChuiZi
JianDao
Bu
JianDao
Bu
ChuiZi
ChuiZi
End

输出样例:

Bu
ChuiZi
Bu
ChuiZi
JianDao
ChuiZi
Bu
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n,cnt=0;string s;cin>>n;while(cin>>s){if(s=="End") break;cnt++;if(cnt>n){cout<<s<<endl;cnt=0;}else if(s=="ChuiZi") cout<<"Bu"<<endl;else if(s=="Bu") cout<<"JianDao"<<endl;else cout<<"ChuiZi"<<endl;}
}

L1-045. 宇宙无敌大招呼

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

据说所有程序员学习的第一个程序都是在屏幕上输出一句“Hello World”,跟这个世界打个招呼。作为天梯赛中的程序员,你写的程序得高级一点,要能跟任意指定的星球打招呼。

输入格式:

输入在第一行给出一个星球的名字S,是一个由不超过7个英文字母组成的单词,以回车结束。

输出格式:

在一行中输出“Hello S”,跟输入的S星球打个招呼。

输入样例:

Mars

输出样例:

Hello Mars
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){string s;cin>>s;cout<<"Hello "<<s<<endl;
}

L1-046. 整除光棍

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
翁恺

这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1、11、111、1111等。传说任何一个光棍都能被一个不以5结尾的奇数整除。比如,111111就可以被13整除。 现在,你的程序要读入一个整数x,这个整数一定是奇数并且不以5结尾。然后,经过计算,输出两个数字:第一个数字s,表示x乘以s是一个光棍,第二个数字n是这个光棍的位数。这样的解当然不是唯一的,题目要求你输出最小的解。

提示:一个显然的办法是逐渐增加光棍的位数,直到可以整除x为止。但难点在于,s可能是个非常大的数 —— 比如,程序输入31,那么就输出3584229390681和15,因为31乘以3584229390681的结果是111111111111111,一共15个1。

输入格式:

输入在一行中给出一个不以5结尾的正奇数x(< 1000)。

输出格式:

在一行中输出相应的最小的s和n,其间以1个空格分隔。

输入样例:

31

输出样例:

3584229390681 15
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){LL n;cin>>n;LL a=1,cnt=1,ans=0,first=0;while(a%n){if(first||a/n) first=1,cout<<a/n;a=a%n;a=a*10+1;cnt++;}if(a/n) cout<<a/n;ans=ans*10+a/n;cout<<" "<<cnt<<endl;
}

L1-047. 装睡

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

你永远叫不醒一个装睡的人 —— 但是通过分析一个人的呼吸频率和脉搏,你可以发现谁在装睡!医生告诉我们,正常人睡眠时的呼吸频率是每分钟15-20次,脉搏是每分钟50-70次。下面给定一系列人的呼吸频率与脉搏,请你找出他们中间有可能在装睡的人,即至少一项指标不在正常范围内的人。

输入格式:

输入在第一行给出一个正整数N(<= 10)。随后N行,每行给出一个人的名字(仅由英文字母组成的、长度不超过3个字符的串)、其呼吸频率和脉搏(均为不超过100的正整数)。

输出格式:

按照输入顺序检查每个人,如果其至少一项指标不在正常范围内,则输出其名字,每个名字占一行。

输入样例:

4
Amy 15 70
Tom 14 60
Joe 18 50
Zoe 21 71

输出样例:

Tom
Zoe
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n;cin>>n;string s;int a,b;vector<string> ans;while(n--){cin>>s>>a>>b;if(a<15||a>20||b<50||b>70) ans.push_back(s);}for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
}

L1-048. 矩阵A乘以B

时间限制
400 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
陈越

给定两个矩阵A和B,要求你计算它们的乘积矩阵AB。需要注意的是,只有规模匹配的矩阵才可以相乘。即若A有Ra行、Ca列,B有Rb行、Cb列,则只有Ca与Rb相等时,两个矩阵才能相乘。

输入格式:

输入先后给出两个矩阵A和B。对于每个矩阵,首先在一行中给出其行数R和列数C,随后R行,每行给出C个整数,以1个空格分隔,且行首尾没有多余的空格。输入保证两个矩阵的R和C都是正数,并且所有整数的绝对值不超过100。

输出格式:

若输入的两个矩阵的规模是匹配的,则按照输入的格式输出乘积矩阵AB,否则输出“Error: Ca != Rb”,其中Ca是A的列数,Rb是B的行数。

输入样例1:

2 3
1 2 3
4 5 6
3 4
7 8 9 0
-1 -2 -3 -4
5 6 7 8

输出样例1:

2 4
20 22 24 16
53 58 63 28

输入样例2:

3 2
38 26
43 -5
0 17
3 2
-11 57
99 68
81 72

输出样例2:

Error: 2 != 3
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main(){int n1,m1,n2,m2;int a[105][105];int b[105][105];int c[105][105];cin>>n1>>m1;for(int i=1;i<=n1;i++)for(int j=1;j<=m1;j++)cin>>a[i][j];cin>>n2>>m2;for(int i=1;i<=n2;i++)for(int j=1;j<=m2;j++)cin>>b[i][j];if(m1!=n2){printf("Error: %d != %d\n",m1,n2);return 0;}for(int i=1;i<=n1;i++){int tmp=0;for(int j=1;j<=m2;j++){for(int k=1;k<=n2;k++){tmp+=a[i][k]*b[k][j];}c[i][j]=tmp;}}cout<<n1<<" "<<m2<<endl;for(int i=1;i<=n1;i++){for(int j=1;j<m2;j++)cout<<c[i][j]<<" ";cout<<c[i][m2]<<endl;}}

团体程序设计天梯赛-练习集 L1合集相关推荐

  1. ptaa乘以b_PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中……)...

    C++ CPP C++语言开发 PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中--) PTA|团体程序设计天梯赛-练习题目题解锦集(持续更新中) 实现语言:C/C++:     ...

  2. PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中……)

    PTA|团体程序设计天梯赛-练习题目题解锦集(持续更新中) 实现语言:C/C++:      欢迎各位看官交流讨论.指导题解错误:或者分享更快的方法!! 题目链接:https://pintia.cn/ ...

  3. L2-010. 排座位-PAT团体程序设计天梯赛GPLT(并查集)

    布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位.无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席. 输入格式: ...

  4. L3-003. 社交集群-PAT团体程序设计天梯赛GPLT(并查集)

    在社交网络平台注册时,用户通常会输入自己的兴趣爱好,以便找到和自己兴趣相投的朋友.有部分兴趣相同的人们就形成了"社交集群".现请你编写程序,找出所有的集群. 输入格式: 输入的第一 ...

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

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

  6. 2020年团体程序设计天梯赛L1题目集(题目+代码)

    2020年11月团体程序设计天梯赛 第一次参加天梯赛,除了在门口冻得瑟瑟发抖,还有按不动的shift之外一切都还好- tip:不知道啥原因代码上基本没有注释,希望dalao们不要介意~ L1-1 嫑废 ...

  7. 【CCCC】PAT : 团体程序设计天梯赛-练习集 L3 答案(01-23)

    [CCCC]PAT : 团体程序设计天梯赛-练习集 L3 答案 顶着满课,整整一星期,终于咕完了.(:´д`)ゞ 知识点分类(23): 1.搜索模拟(5):BFS,DFS,最短路,路径打印 2.计算几 ...

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

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

  9. PTA|团体程序设计天梯赛-练习题库集

    文章目录 关于爬取脚本的编写 L1-001 Hello World! (5 分) L1-002 打印沙漏 (15 分) L1-003 个位数统计 (15 分) L1-004 计算摄氏温度 (5 分) ...

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

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

最新文章

  1. 03-kubeadm初始化Kubernetes集群
  2. mysql my.cnf 官网_MySQL my.cnf 的配置
  3. 指针08 - 零基础入门学习C语言48
  4. 相片堆叠瀑布流网格布局动画效果
  5. 图的深度优先搜索遍历
  6. macos 升级后 从前的 apachectl 错误, php 错误
  7. Swagger写的接口的输入参数是对象的处理方法!通俗易懂(图文并茂), 小白与大佬之间的对话!
  8. 魔兽世界服务端linux,mmorpg魔兽世界服务器框架TrinityCore构建
  9. .NetCore对接各大财务软件凭证API——金蝶系列(2)
  10. 代码封装的思想,竟然在中国古代就已经存在了
  11. [源码解读]一文彻底搞懂Events模块
  12. 英语单词常见词根总结
  13. Input框内容改变触发事件,实现表格动态模糊查询
  14. 最小二乘估计,矩阵求导法(正规方程)全推导
  15. ANTLR4 入门学习(一):下载和测试
  16. 攻防世界reverse高手进阶 ----- gametime
  17. mysql数据库中查询第几条到第几条数据_在 mysql 数据库中,从查询结果的第四条记录开始选取5条记录,下面 sql 语句正确的是( )...
  18. setContextProperty qmlRegisterType qRegisterMetaType等区别
  19. 自动买卖炒股软件的设置条件?
  20. 制作一款STC32G封装为TSSOP20的测试电路板

热门文章

  1. pq和mysql_Go实战--go语言操作PostgreSQL数据库(github.com/lib/pq)
  2. QQ 登录/分享接入流程
  3. JS获取指定时间内的所有星期五
  4. 计算机病毒感染exe过程,电脑病毒传染过程
  5. 百世快递快速的查询并导出csv表格?
  6. C#按比例缩放窗体控件及字体
  7. 【必读】计算机专业学生一定要学好哪些课程?
  8. 引用了撤稿文章, 该如何应对?
  9. 《python语言程序设计基础》—— 第7章
  10. 成品app直播源码,Android防止多次点击