首页 > 编程语言 >【CCCC】PAT : 团体程序设计天梯赛-练习集 L1 答案

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

时间:2023-02-08 21:07:11浏览次数:71  
标签:PAT cout int namespace cin CCCC L1 return


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

鉴定完毕,全部水题 ヾ(•ω•`)o

标号

标题

分数

通过数

提交数

通过率

L1-001

​Hello World​

5

46779

112778

0.41

L1-002

​打印沙漏​

20

20237

83655

0.24

L1-003

​个位数统计​

15

20404

65549

0.31

L1-004

​计算摄氏温度​

5

24244

74781

0.32

L1-005

​考试座位号​

15

15518

50428

0.31

L1-006

​连续因子​

20

11949

52172

0.23

L1-007

​念数字​

10

16522

52075

0.32

L1-008

​求整数段和​

10

15060

66897

0.23

L1-009

​N个数求和​

20

9638

60667

0.16

L1-010

​比较大小​

10

15540

38538

0.40

L1-011

​A-B​

20

11898

47991

0.25

L1-012

​计算指数​

5

16607

47310

0.35

L1-013

​计算阶乘和​

10

14480

27237

0.53

L1-014

​简单题​

5

16854

24068

0.70

L1-015

​跟奥巴马一起画方块​

15

12927

34714

0.37

L1-016

​查验身份证​

15

9851

31292

0.31

L1-017

​到底有多二​

15

10480

38120

0.27

L1-018

​大笨钟​

10

11624

37516

0.31

L1-019

​谁先倒​

15

8846

29343

0.30

L1-020

​帅到没朋友​

20

8467

43250

0.20

L1-021

​重要的话说三遍​

5

14685

24193

0.61

L1-022

​奇偶分家​

10

11361

21585

0.53

L1-023

​输出GPLT​

20

8285

22037

0.38

L1-024

​后天​

5

12956

29766

0.44

L1-025

​正整数A+B​

15

7430

44383

0.17

L1-026

​I Love GPLT​

5

12588

31065

0.41

L1-027

​出租​

20

6968

14624

0.48

L1-028

​判断素数​

10

11228

60552

0.19

L1-029

​是不是太胖了​

5

11830

24762

0.48

L1-030

​一帮一​

15

7967

17498

0.46

L1-031

​到底是不是太胖了​

10

9399

34391

0.27

L1-032

​Left-pad​

20

7210

23280

0.31

L1-033

​出生年​

15

6747

15249

0.44

L1-034

​点赞​

20

6337

13197

0.48

L1-035

​情人节​

15

7044

18644

0.38

L1-036

​A乘以B​

5

11514

18152

0.63

L1-037

​A除以B​

10

9116

25169

0.36

L1-038

​新世界​

5

10515

14596

0.72

L1-039

​古风排版​

20

6973

28987

0.24

L1-040

​最佳情侣身高差​

10

8786

20637

0.43

L1-041

​寻找250​

10

8703

20301

0.43

L1-042

​日期格式化​

5

9734

21954

0.44

L1-043

​阅览室​

20

5046

23234

0.22

L1-044

​稳赢​

15

6085

20215

0.30

L1-045

​宇宙无敌大招呼​

5

9944

20542

0.48

L1-046

​整除光棍​

20

5555

14929

0.37

L1-047

​装睡​

10

7819

15067

0.52

L1-048

​矩阵A乘以B​

15

5523

17281

0.32

L1-049

​天梯赛座位分配​

20

4474

15545

0.29

L1-050

​倒数第N个字符串​

15

5678

13331

0.43

L1-051

​打折​

5

9542

19821

0.48

L1-052

​2018我们要赢​

5

9616

14118

0.68

L1-053

​电子汪​

10

7799

12047

0.65

L1-054

​福到了​

15

5655

17179

0.33

L1-055

​谁是赢家​

10

6763

18026

0.38

L1-056

​猜数字​

20

6204

19732

0.31

L1-057

​PTA使我精神焕发​

5

6543

8880

0.74

L1-058

​6翻了​

15

4275

12787

0.33

L1-059

​敲笨钟​

20

3528

11196

0.32

L1-060

​心理阴影面积​

5

5290

10713

0.49

L1-061

​新胖子公式​

10

4378

10038

0.44

L1-062

​幸运彩票​

15

3687

8192

0.45

L1-063

​吃鱼还是吃肉​

10

4108

10967

0.37

L1-064

​估值一亿的AI核心代码​

20

2561

15261

0.17

L1-AC代码

L1-001

#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello World!";
return 0;
}

L1-002

#include<bits/stdc++.h>
using namespace std;
int main(){
int n; char ch;
cin>>n>>ch;
int h = sqrt((n+1)/2);
for(int i = h; i >= 1; i--){
for(int j = 1; j <= h-i; j++)cout<<" ";
for(int j = 1; j <= 2*i-1; j++)cout<<ch;
cout<<"\n";
}
for(int i = 2; i <= h; i++){
for(int j = 1; j <= h-i; j++)cout<<" ";
for(int j = 1; j <= 2*i-1; j++)cout<<ch;
cout<<"\n";
}
cout<<n+1-2*h*h<<endl;
return 0;
}

L1-003

#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
string s; cin>>s;
for(int i = 0; i < s.size(); i++){
a[s[i]-'0']++;
}
for(int i = 0; i <= 9; i++){
if(a[i]){
cout<<i<<":"<<a[i]<<"\n";
}
}
return 0;
}

L1-004

#include<bits/stdc++.h>
using namespace std;
int main(){
int f, c;
cin>>f;
c = 5*(f-32)/9;
cout<<"Celsius = "<<c<<endl;
return 0;
}

L1-005

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
string ha[maxn]; int ha2[maxn];
int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
string a; int b, c;
cin>>a>>b>>c;
ha[b] = a;
ha2[b] = c;
}
int q; cin>>q;
for(int i = 1; i <= q; i++){
int x; cin>>x;
cout<<ha[x]<<" "<<ha2[x]<<"\n";
}
return 0;
}

L1-006

#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n; cin>>n;
int star=0, len=0;
int t = sqrt(n)+1;
for(int i = 2; i <= t; i++){
int tmp = 1, j;
for(j = i; j <= t; j++){
tmp *= j;
if(n%tmp != 0)break;
}
if(j-i>len){
star = i;
len = j-i;
}
}
if(star == 0){
cout<<1<<endl;
cout<<n<<endl;
}else{
cout<<len<<endl;
for(int i = 0; i < len-1; i++)
cout<<star+i<<"*";
cout<<star+len-1;
}
return 0;
}

L1-007

#include<bits/stdc++.h>
using namespace std;
string s[11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main(){
string a; cin>>a;
for(int i = 0; i < a.size(); i++){
if(i!=0)cout<<" ";
if(a[i]=='-'){
cout<<"fu";
continue;
}
cout<<s[a[i]-'0'];
}
return 0;
}

L1-008

#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin>>a>>b;
int cnt = 0, sum = 0;
for(int i = a; i <= b; i++){
printf("%5d",i);
sum += i;
cnt++;
if(cnt%5==0){
cout<<"\n";
}
}
if(cnt%5!=0)cout<<"\n";
cout<<"Sum = "<<sum<<"\n";
return 0;
}

L1-009

#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int main(){
int n; cin>>n;
int a, b, c=0, d=1;
for(int i = 1; i <= n; i++){
cin>>a; cin.get(); cin>>b;
c = c*b+a*d;
d *= b;
int g = abs(gcd(c,d));
c /= g;
d /= g;
}
if(c==0){ cout<<"0\n"; return 0;}
if(c<0){cout<<"-";c=-c;}
if(c<d){printf("%d/%d",c,d);return 0;}
if(c==d){cout<<"1";return 0;}
if(c>d)cout<<(c/d);
if(c%d!=0)printf(" %d/%d",c%d,d);
return 0;
}

L1-010

#include<bits/stdc++.h>
using namespace std;
int a[5];
int main(){
cin>>a[1]>>a[2]>>a[3];
sort(a+1,a+4);
cout<<a[1]<<"->"<<a[2]<<"->"<<a[3]<<endl;
return 0;
}

L1-011

#include<bits/stdc++.h>
using namespace std;
int main(){
string a, b;
getline(cin,a);
getline(cin,b);
for(int i = 0; i < a.size(); i++){
if(b.find(a[i])!=string::npos)continue;
cout<<a[i];
}
return 0;
}

L1-012

#include<bits/stdc++.h>
using namespace std;
int main(){
long long n; cin>>n;
printf("2^%lld = %lld\n",n,(1<<n));
return 0;
}

L1-013

#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int sum = 0;
for(int i = 1; i <= n; i++){
int t = 1;
for(int j = 1; j <= i; j++){
t *= j;
}
sum += t;
}
cout<<sum<<endl;
return 0;
}

L1-014

#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"This is a simple problem.";
return 0;
}

L1-015

#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int m = n*10/2;
if(m%10>=5)m=m/10+1;
else m = m/10;
char ch; cin>>ch;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++)
putchar(ch);
putchar('\n');
}
return 0;
}

L1-016

#include<bits/stdc++.h>
using namespace std;

int pows[] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
string m = "10X98765432";

int main(){
int n; cin>>n;
int ok = 1;
for(int i = 1; i <= n; i++){
string s; cin>>s;
int z = 0;
for(int j = 0; j < 17; j++)
z += (s[j]-'0')*pows[j];
z %= 11;
if(s[17]!=m[z]){
cout<<s<<endl;
ok = 0;
}
}
if(ok)cout<<"All passed\n";
return 0;
}

L1-017

#include<bits/stdc++.h>
using namespace std;

int main(){
string s; cin>>s;

double bt = 1;
if(s[0]=='-'){bt *= 1.5; s=s.substr(1);}
if(s[s.size()-1]%2==0)bt *= 2;

int cnt = 0;
for(int i = 0; i < s.size(); i++)
if(s[i]=='2')cnt++;

printf("%.2lf%\n",cnt*100.0/s.size()*bt);
return 0;
}

L1-018

#include<bits/stdc++.h>
using namespace std;

int main(){
int a, b; char ch;
cin>>a>>ch>>b;
if(a>=0 && a<12 || a==12&&b==0){
printf("Only %02d:%02d. Too early to Dang.",a,b);
return 0;
}
int cc = a-12;
if(b>0)cc++;
for(int i = 1; i <= cc; i++)
cout<<"Dang";
return 0;
}

L1-019

#include<bits/stdc++.h>
using namespace std;

int main(){
int A, B, n;
cin>>A>>B>>n;
int AA = A, BB = B;
for(int i = 1; i <= n; i++){
int a, b, c, d;
cin>>a>>b>>c>>d;
int cc = 0;
if(b==a+c)cc++;
if(d==a+c)cc--;
if(cc>0)A--;
if(cc<0)B--;
if(A<0 || B<0)break;
}
if(A<0)cout<<"A\n"<<BB-B;
else cout<<"B\n"<<AA-A;
return 0;
}

L1-020

#include<bits/stdc++.h>
using namespace std;

int main(){
int n; cin>>n;
set<string>s;
for(int i = 1; i <= n; i++){
int k; cin>>k;
string st;
if(k>=2){
for(int j = 0; j < k; j++){
cin>>st; s.insert(st);
}
}else{
cin>>st;
}
}
int q; cin>>q;
set<string>repe; int ok = 0;
for(int i = 1; i <= q; i++){
string st; cin>>st;
if(s.find(st)==s.end() && repe.find(st)==repe.end()){
repe.insert(st);
if(ok)cout<<" ";
cout<<st;
ok = 1;
}
}
if(!ok)cout<<"No one is handsome\n";
return 0;
}

L1-021

#include<bits/stdc++.h>
using namespace std;

int main(){
for(int i = 1; i <= 3; i++)
printf("I'm gonna WIN!\n");

return 0;
}

L1-022

#include<bits/stdc++.h>
using namespace std;

int main(){
int n; cin>>n;
int cnt = 0;
for(int i = 1; i <= n; i++){
int x; cin>>x;
if(x%2==1)cnt++;
}
cout<<cnt<<" "<<n-cnt<<endl;
return 0;
}

L1-023

#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
string s; cin>>s;
for(int i = 0; i < s.size(); i++){
if(islower(s[i]))s[i] = s[i]-('a'-'A');
a[s[i]-'A']++;
}
while(a['G'-'A'] || a['P'-'A'] || a['L'-'A'] || a['T'-'A']){
if(a['G'-'A']){cout<<"G";a['G'-'A']--;}
if(a['P'-'A']){cout<<"P";a['P'-'A']--;}
if(a['L'-'A']){cout<<"L";a['L'-'A']--;}
if(a['T'-'A']){cout<<"T";a['T'-'A']--;}
}
return 0;
}

L1-024

#include<bits/stdc++.h>
using namespace std;

int main(){
int n; cin>>n;
cout<<(n+1)%7+1;
return 0;
}

L1-025

#include<bits/stdc++.h>
using namespace std;

int main(){
string s; getline(cin,s);
string a = s.substr(0,s.find(' '));
string b = s.substr(s.find(' ')+1);
int aa=-1, bb=-1;
int ok = 1;
for(int i = 0; i < a.size(); i++)
if(!isdigit(a[i]))ok = 0;
if(ok && stoi(a)>=1 && stoi(a)<=1000)aa = stoi(a);
ok = 1;
for(int i = 0; i < b.size(); i++)
if(!isdigit(b[i]))ok = 0;
if(ok && stoi(b)>=1 && stoi(b)<=1000)bb = stoi(b);
if(aa!=-1)cout<<aa;else cout<<"?";
cout<<" + ";
if(bb!=-1)cout<<bb;else cout<<"?";
cout<<" = ";
if(aa!=-1&&bb!=-1)cout<<aa+bb;
else cout<<"?";
return 0;
}

L1-026

#include<bits/stdc++.h>
using namespace std;

int main(){
string s = "I Love GPLT";
for(int i = 0; i < s.size(); i++){
cout<<s[i]<<"\n";
}
return 0;
}

L1-027

#include<bits/stdc++.h>
using namespace std;

int a[11];
int main(){
string s; cin>>s;
for(int i = 0; i < s.size(); i++)
a[s[i]-'0']++;
cout<<"int[] arr = new int[]{";
int ok = 0; vector<int>vec;
for(int i = 9; i >= 0; i--){
if(a[i]){
if(ok)cout<<",";
cout<<i;
ok = 1;
vec.push_back(i);
}
}
cout<<"};\n";
cout<<"int[] index = new int[]{";
for(int i = 0; i < s.size(); i++){
if(i!=0)cout<<",";
cout<<find(vec.begin(),vec.end(),s[i]-'0')-vec.begin();
}
cout<<"};\n";
return 0;
}

L1-028

#include<bits/stdc++.h>
using namespace std;

int main(){
int T; cin>>T;
while(T--){
int n; cin>>n;
int prime = 1;
if(n==1)prime = 0;
for(int i = 2; i <= sqrt(n); i++){
if(n%i==0){
prime = 0;
break;
}
}
if(prime)cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}

L1-029

#include<bits/stdc++.h>
using namespace std;

int main(){
int h; cin>>h;
printf("%.1f",(h-100)*0.9*2.0);
return 0;
}

L1-030

#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
int main(){
int n; cin>>n;
string nm[maxn]; int sex[maxn], vis[maxn];
memset(vis,0,sizeof(vis));
for(int i = 1; i <= n; i++){
int x; cin>>x; sex[i] = x;
string s; cin>>s; nm[i] = s;
}
for(int i = 1; i <= n; i++){
if(!vis[i]){
for(int j = n; j >= 1; j--){
if(!vis[j] && sex[i]!=sex[j]){
cout<<nm[i]<<" "<<nm[j]<<"\n";
vis[i] = vis[j] = 1;
break;
}
}
}
}
return 0;
}

L1-031

#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
int main(){
int T; cin>>T;
while(T--){
double h, w; cin>>h>>w;
double s = (h-100)*0.9*2.0;
if(abs(s-w)<s*0.1){
cout<<"You are wan mei!\n";
continue;
}
if(w>s)
cout<<"You are tai pang le!\n";
else
cout<<"You are tai shou le!\n";
}
return 0;
}

L1-032

#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
int main(){
int T; cin>>T;
while(T--){
double h, w; cin>>h>>w;
double s = (h-100)*0.9*2.0;
if(abs(s-w)<s*0.1){
cout<<"You are wan mei!\n";
continue;
}
if(w>s)
cout<<"You are tai pang le!\n";
else
cout<<"You are tai shou le!\n";
}
return 0;
}

L1-033

#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
int main(){
int x, n, y;
cin>>x>>n;
int xx = x;
while(1){
set<int>se;
int t = x;
for(int i = 0; i < 4; i++){
se.insert(t%10);
t /= 10;
}
if(se.size()==n){
y = x;
break;
}
x++;
}
printf("%d %04d",y-xx,y);
return 0;
}

L1-034

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn];
int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
int k; cin>>k;
for(int j = 1; j <= k; j++){
int x; cin>>x; a[x]++;
}
}
int mx = -1e9, cc;
for(int i = 0; i <= maxn; i++){
if(a[i]>=mx){
mx = a[i];
cc = i;
}
}
cout<<cc<<" "<<mx;
return 0;
}

L1-035

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
string a="", b="";
for(int i = 1; i <= 14; i++){
string x; cin>>x;
if(x==".")break;
if(i==2)a = x;
if(i==14)b = x;
}
if(a!=""&&b!="")
cout<<a<<" and "<<b<<" are inviting you to dinner...\n";
else if(a!=""&&b=="")
cout<<a<<" is the only one for you...\n";
else
cout<<"Momo... No one is for you ...\n";
return 0;
}

L1-036

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
int a, b;
cin>>a>>b;
cout<<a*b;
return 0;
}

L1-037

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
int a, b; cin>>a>>b;
if(b>0){
printf("%d/%d=%.2f\n",a,b,a*1.0/b);
}else if(b==0){
printf("%d/0=Error\n",a);
}else{
printf("%d/(%d)=%.2f",a,b,a*1.0/b);
}
return 0;
}

L1-038

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
cout<<"Hello World\n";
cout<<"Hello New World\n";
return 0;
}

L1-039

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
int n; cin>>n; cin.get();
string s; getline(cin,s);
//cout<<s<<endl;
int x;
if(s.size()%n==0)x = s.size()/n;
else x = s.size()/n+1;
string ans[1000];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= x; j++){
ans[i][j] = ' ';
}
}
int cc = 0;
for(int i = x; i >= 1; i--){
for(int j = 1; j <= n; j++){
if(cc>=s.size())break;
ans[j][i] = s[cc++];
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= x; j++){
cout<<ans[i][j];
}
cout<<"\n";
}
return 0;
}

L1-040

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
int T; cin>>T;
while(T--){
char a; double b;
cin>>a>>b;
//cout<<a<<" "<<b<<endl;
if(a=='M')printf("%.2lf\n",b/1.09);
else printf("%.2lf\n",b*1.09);
}
return 0;
}

L1-041

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
int x, i;
for(i = 1; x!=250; i++)
cin>>x;
cout<<i-1;
return 0;
}

L1-042

#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
scanf("%d-%d-%d",&a,&b,&c);
printf("%04d-%02d-%02d\n",c,a,b);
return 0;
}

L1-043

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
struct node{int s=-1, t=-1, ti=0;}book[maxn];
int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
int x; char op; int hh, mm;
int ans = 0, cnt = 0;
while(scanf("%d %c %d:%d",&x,&op,&hh,&mm) &&x){
//cout<<x<<" "<<op<<" "<<hh<<" "<<mm<<"\n";
if(op=='S'){
book[x].s = hh*60+mm;
}else if(book[x].s!=-1){
book[x].t = hh*60+mm;
ans += book[x].t-book[x].s;
book[x].s = -1; //WA1,3又还了一次
cnt++;
}
}
if(ans!=0)printf("%d %d\n",cnt,(int)(ans*1.0/cnt+0.5));
else printf("0 0\n");
}
return 0;
}

L1-044

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
map<string, string>ma;
int main(){
ma["ChuiZi"] = "Bu";
ma["JianDao"] = "ChuiZi";
ma["Bu"] = "JianDao";
//freopen("input.txt","r",stdin);
int k; cin>>k;
string s; int cnt = 0;
while(cin>>s&&s!="End"){
if(cnt==k){
cout<<s<<"\n";
cnt = 0;
}else{
cout<<ma[s]<<"\n";
cnt++;
}
}
return 0;
}

L1-045

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
int main(){
string s; cin>>s;
cout<<"Hello "<<s;
return 0;
}

L1-046

//每次余数末位添1去运算,就不用写高精除法和取模了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
int main(){
int x, s = 0, n = 0;
cin>>x;
while(s<x){s=s*10+1;n++;}
while(1){
cout<<s/x;
s %= x;//被除数更新为余数
if(s==0)break;
s = s*10+1;//余数加1位
n++;
}
cout<<" "<<n;
return 0;
}

L1-047

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
string nm; int huxi, maibo;
cin>>nm>>huxi>>maibo;
if(huxi<15||huxi>20||maibo<50||maibo>70){
cout<<nm<<"\n";
}
}
return 0;
}

L1-048

//乘积C的第m行第n列的元素等于矩阵A的第m行的元素与矩阵B的第n列对应元素乘积之和
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1010;
int a[maxn][maxn], b[maxn][maxn];
int main(){
int Ra, Ca, Rb, Cb;
cin>>Ra>>Ca;
for(int i = 1; i <= Ra; i++)
for(int j =1; j <= Ca ;j++)
cin>>a[i][j];
cin>>Rb>>Cb;
for(int i = 1; i <= Rb; i++)
for(int j =1; j<=Cb; j++)
cin>>b[i][j];
if(Ca!=Rb)cout<<"Error: "<<Ca<<" != "<<Rb<<"\n";
else{
cout<<Ra<<" "<<Cb<<"\n";
for(int i = 1; i <= Ra; i++){
for(int j = 1; j <= Cb; j++){
int sum = 0;
for(int k = 1; k <= Ca; k++)
sum += a[i][k]*b[k][j];
if(j!=1)cout<<" ";
cout<<sum;
}
cout<<"\n";
}
}
return 0;
}

L1-049

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, m[maxn], seat[maxn*maxn];
vector<int>id[maxn];
int main(){
cin>>n;
for(int i = 1; i <= n; i++)
cin>>m[i];
int cnt = 1;
while(1){
int ok = 1;
for(int i = 1; i <= n; i++){
if(id[i].size()>=m[i]*10)continue;
if(seat[cnt-1]!=i){
seat[cnt] = i;
id[i].push_back(cnt);
cnt++;
}else{
seat[cnt+1] = i;
id[i].push_back(cnt+1);
cnt+=2;
}
ok = 0;
}
if(ok)break;
}
for(int i = 1; i <= n; i++){
cout<<"#"<<i<<endl;
for(int j = 0; j < id[i].size(); j++){
if(j!=0 && j%10!=0)cout<<" ";
if(j!=0 && j%10==0)cout<<"\n";
cout<<id[i][j];
}
cout<<"\n";
}
return 0;
}

L1-050

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
int L, n; cin>>L>>n;
n = pow(26,L)-n;
//26进制转10进制
vector<int>v;
while(n){
v.push_back(n%26);
n /= 26;
}
//位数不够补0(a)
for(int i = 0; i < L-v.size(); i++)
cout<<'a';
for(int i = v.size()-1; i >= 0; i--)
cout<<(char)('a'+v[i]);
return 0;
}

L1-051

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
int n, x;
cin>>n>>x;
double ans = n*1.0*x/10.0;
printf("%.2lf",ans);
return 0;
}

L1-052

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
cout<<"2018\nwo3 men2 yao4 ying2 !\n";
return 0;
}

L1-053

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
int a, b;
cin>>a>>b;
for(int i = 1; i <= a+b; i++)
cout<<"Wang!";

return 0;
}

L1-054

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
int n; char ch;
cin>>ch>>n; cin.get();
vector<string>v1,v2;
for(int i = 1; i <= n; i++){
string tmp; getline(cin,tmp);
v1.push_back(tmp);
reverse(tmp.begin(),tmp.end());
v2.push_back(tmp);
}
reverse(v2.begin(),v2.end());
int ok = 1;
for(int i = 0; i < v1.size(); i++)
if(v1[i]!=v2[i])ok = 0;
if(ok)cout<<"bu yong dao le\n";
for(int i = 0; i < v2.size(); i++){
for(int j = 0; j < v2[i].size(); j++){
if(v2[i][j]=='@')cout<<ch;
else cout<<" ";
}
cout<<"\n";
}
return 0;
}

L1-055

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

int main(){
int pa, pb, x1, x2, x3;
cin>>pa>>pb>>x1>>x2>>x3;
int a = x1+x2+x3, b = 3-a;
if((pa>pb&&b>=1) || (pa<pb&&b==3)){
cout<<"The winner is a: "<<pa<<" + "<<b<<"\n";
}else{
cout<<"The winner is b: "<<pb<<" + "<<a<<"\n";
}
return 0;
}

L1-056

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
struct node{string name; int num; }a[maxn];
int main(){
int n; cin>>n;
int sum = 0;
for(int i = 1; i <= n; i++){
cin>>a[i].name>>a[i].num;
sum += a[i].num;
}
int avg = (sum/n)/2, mi = 1e9+10, t;
for(int i = 1; i <= n; i++){
if(abs(avg-a[i].num)<mi){
mi = abs(avg-a[i].num);
t = i;
}
}
cout<<avg<<" "<<a[t].name<<"\n";
return 0;
}

L1-057

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
cout<<"PTA shi3 wo3 jing1 shen2 huan4 fa1 !\n";
return 0;
}

L1-058

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;

int main(){
string s; getline(cin,s);
for(int i = 0; i < s.size(); i++){
if(s[i]!='6')cout<<s[i];
else{
int cc = i;
while(s[cc]=='6' && cc<s.size())cc++;
if(cc-i>9)cout<<"27";
else if(cc-i>3)cout<<"9";
else cout<<s.substr(i,cc-i);
i = cc-1;
}
}
return 0;
}

L1-059

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
int n; cin>>n; cin.get();
for(int i = 1; i <= n; i++){
string s; getline(cin,s);
if(s.find("ong,")==string::npos||s.find("ong.")==string::npos){
cout<<"Skipped\n";
continue;
}
int d = s.find(','), ju = s.find('.');
if(s.substr(d-3,3)!="ong" || s.substr(ju-3,3)!="ong")
cout<<"Skipped\n";
else{
int jj = ju, cc = 0;
while(cc<3 && jj>=0)if(s[jj--]==' ')cc++;
cout<<s.substr(0,jj+1)<<" qiao ben zhong.\n";
}
}
return 0;
}

L1-060

#include <bits/stdc++.h>
using namespace std;
int main(){
int x, y; cin>>x>>y;
printf("%d",100*100/2-100*(100-x)/2-100*y/2);
return 0;
}

L1-061

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
double x, y;
cin>>x>>y;
double z = x/y/y;
printf("%.1lf\n",z);
if(z>25.0){
cout<<"PANG\n";
}else{
cout<<"Hai Xing\n";
}
return 0;
}

L1-062

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
string s; cin>>s;
int a = 0, b = 0;
for(int j = 0; j < 3; j++)a+=s[j]-'0';
for(int j = 3; j < 6; j++)b+=s[j]-'0';
if(a==b){
cout<<"You are lucky!\n";
}else{
cout<<"Wish you good luck.\n";
}
}
return 0;
}

L1-063

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
int sx, hei, wei;
cin>>sx>>hei>>wei;
if(sx==1){
if(hei==130)cout<<"wan mei! ";
else if(hei<130)cout<<"duo chi yu! ";
else cout<<"ni li hai! ";

if(wei==27)cout<<"wan mei!\n";
else if(wei<27)cout<<"duo chi rou!\n";
else cout<<"shao chi rou!\n";
}else{
if(hei==129)cout<<"wan mei! ";
else if(hei<129)cout<<"duo chi yu! ";
else cout<<"ni li hai! ";

if(wei==25)cout<<"wan mei!\n";
else if(wei<25)cout<<"duo chi rou!\n";
else cout<<"shao chi rou!\n";
}
}
return 0;
}

L1-064

//大小写直接扫一遍处理。符号前面加空格当单词特判。空格用string流重新读一遍处理掉。
#include<bits/stdc++.h>
using namespace std;
int main(){
//freopen("input.txt","w",stdout);
int n=-1; cin>>n; cin.get();
for(int i = 1; i <= n; i++){
string s; getline(cin,s);
cout<<s<<endl<<"AI:";

for(int j = 0; j < s.size(); j++){
if(isalnum(s[j]) && s[j]!='I')
s[j] = tolower(s[j]);
else if(!isalnum(s[j]))//符号前面加空格分隔
s.insert(j," "),j++;
if(s[j]=='?')
s[j] = '!';
}

string ans[1010];
int cnt = 0;
stringstream ss(s);
while(ss>>s)ans[cnt++] = s;

if(!isalnum(ans[0][0]))//RE or PE
cout<<" ";
for(int j = 0; j < cnt; j++){
if(!isalnum(ans[j][0]))
cout<<ans[j];//除了第一个,符号前不加空格
else if(ans[j]=="can"&&ans[j+1]=="you"){
cout<<" I can"; j++;
}else if(ans[j]=="could"&&ans[j+1]=="you"){
cout<<" I could"; j++;
}else if(ans[j]=="I" || ans[j]=="me"){
cout<<" you";
}else {
cout<<" "<<ans[j];
}
}
cout<<"\n";

}
return 0;
}


标签:PAT,cout,int,namespace,cin,CCCC,L1,return
From: https://blog.51cto.com/gwj1314/6044875

相关文章