L1-001 Hello World (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805147132084224
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("Hello World!\n"); return 0; }
L1-002 打印沙漏 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805145370476544
思路:利用等差數列求和,算出利用當前N 最多可以搭建的層數(單側) 然后模擬
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; char x; int main(){ scanf("%d %c",&n,&x); int pos=0; while(((3+(2*pos+1))*pos+2*(2*(pos+1)+1))<(n-1)){ pos++; } // printf("%d\n",pos); for(int i=0;i<=pos;i++){ for(int j=0;j<i;j++){ printf(" "); } for(int j=0;j<2*pos+1-2*i;j++){ printf("%c",x); } printf("\n"); } for(int i=pos-1;i>=0;i--){ for(int j=0;j<i;j++){ printf(" "); } for(int j=0;j<2*pos+1-2*i;j++){ printf("%c",x); } printf("\n"); } printf("%d\n",n-((3+2*pos+1)*pos+1)); return 0; }
L1-003 個位數統計 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805143738892288
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int cnt[15]; char s[maxn]; int main(){ scanf("%s",s); int len=strlen(s); memset(cnt,0,sizeof(cnt)); for(int i=0;i<len;i++){ cnt[s[i]-'0']++; } for(int i=0;i<=9;i++){ if(cnt[i]!=0) printf("%d:%d\n",i,cnt[i]); } return 0; }
L1-004 計算攝氏溫度 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805142086336512
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); printf("Celsius = %d\n",5*(n-32)/9); return 0; }
L1-005 考試座位號 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805140211482624
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int n,m,x; struct node{ char a[50]; int b,c; }kk[maxn]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s %d %d",kk[i].a,&kk[i].b,&kk[i].c); } scanf("%d",&m); for(int i=1;i<=m;i++){ scanf("%d",&x); for(int j=1;j<=n;j++){ if(x==kk[j].b){ printf("%s %d\n",kk[j].a,kk[j].c); } } } return 0; }
L1-006 連續因子 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805138600869888
思路:枚舉可能開始連續的位置j 對於每個j都判斷能否組成N 如果可以 紀錄長度取max
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; ll n; int main(){ scanf("%lld",&n); ll sum=0; int st=0,len=0; for(int i=2;i<=sqrt(n);i++){ sum=1; for(int j=i;j*sum<=n;j++){ sum*=j; if(n%sum==0 && j-i+1>len){ st=i; len=j-i+1; } } } if(st==0){ st=n; len=1; } printf("%d\n%d",len,st); for(int i=st+1;i<st+len;i++){ printf("*%d",i); } printf("\n"); return 0; }
L1-007 念數字 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805136889593856
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; char n[1010]; int main(){ scanf("%s",n); int len=strlen(n); string s[11]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; if(n[0]=='-'){ printf("fu "); for(int i=1;i<len-1;i++){ cout<<s[n[i]-'0']<<" "; } cout<<s[n[len-1]-'0']<<endl; } else{ for(int i=0;i<len-1;i++){ cout<<s[n[i]-'0']<<" "; } cout<<s[n[len-1]-'0']<<endl; } return 0; }
L1-008 求整數段和 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805135224455168
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int a,b; int main(){ scanf("%d%d",&a,&b); int cnt=0,sum=0; for(int i=a;i<=b;i++){ cnt++; sum+=i; printf("%5d",i); if(cnt==5){ printf("\n"); cnt=0; } } if((b-a+1)%5!=0) printf("\n"); printf("Sum = %d\n",sum); return 0; }
L1-009 N個數求和 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805133597065216
思路:在通分的時候會爆int 選擇了用long double 先除后乘
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=110; int n; ll a[maxn],b[maxn]; int main(){ (void)scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lld/%lld",&a[i],&b[i]); } ll sum1=a[1],sum2=b[1]; for(int i=2;i<=n;i++){ ll tmp=__gcd(sum2,b[i]); ll ans=(long double)sum2/(long double)tmp*b[i]; sum1=(long double)a[i]/(long double)b[i]*ans+(long double)sum1/(long double)sum2*ans; sum2=ans; ll tmp2=__gcd(sum1,sum2); //int ans2=sum1*sum2/tmp2; sum1/=tmp2; sum2/=tmp2; } ll t=0; t=sum1/sum2; sum1-=t*sum2; if(t==0 && sum1!=0) printf("%lld/%lld\n",sum1,sum2); else if(t!=0 && sum1!=0) printf("%lld %lld/%lld\n",t,sum1,sum2); else if(sum1==0) printf("%lld\n",t); return 0; }
L1-010 比較大小 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805132040978432
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int a[5]; int main(){ 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 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805130426171392
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int cnt[300]; string a,b; int main(){ getline(cin,a); getline(cin,b); for(int i=0;i<b.length();i++){ cnt[b[i]]=1; } for(int i=0;i<a.length();i++){ if(cnt[a[i]]==1) continue; cout<<a[i]; } cout<<endl; return 0; }
L1-012 計算指數 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805128870084608
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int a=pow(2,n); printf("2^%d = %d\n",n,a); return 0; }
L1-013 計算階乘和 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805127389495296
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ int tmp=1; for(int j=1;j<=i;j++){ tmp*=j; } sum+=tmp; } printf("%d\n",sum); return 0; }#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ int tmp=1; for(int j=1;j<=i;j++){ tmp*=j; } sum+=tmp; } printf("%d\n",sum); return 0; }#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ int tmp=1; for(int j=1;j<=i;j++){ tmp*=j; } sum+=tmp; } printf("%d\n",sum); return 0; }#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ int tmp=1; for(int j=1;j<=i;j++){ tmp*=j; } sum+=tmp; } printf("%d\n",sum); return 0; }#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ int tmp=1; for(int j=1;j<=i;j++){ tmp*=j; } sum+=tmp; } printf("%d\n",sum); return 0; }
L1-014 簡單題 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805125929877504
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("This is a simple problem.\n"); return 0; }
L1-015 跟奧巴馬一起畫方塊 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805124398956544
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; char x; int main(){ scanf("%d %c",&n,&x); int m; if(n%2==1) m=n/2+1; else m=n/2; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ printf("%c",x); } printf("\n"); } return 0; }
L1-016 查驗身份證 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805122985476096
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,ans[110]; char s[110][50]; const int a[18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; const int b[12]={1,0,'X'-'0',9,8,7,6,5,4,3,2}; int main(){ scanf("%d",&n); int flag=0; for(int id=1;id<=n;id++){ scanf("%s",s[id]); int sum=0,cnt=0; for(int i=0;i<17;i++){ if(s[id][i]-'0'<0 || s[id][i]-'0'>9) cnt++; else sum+=((s[id][i]-'0')*a[i]); } // printf("%d\n",cnt); if(cnt!=0){ ans[flag++]=id; continue; } else{ sum%=11; if(s[id][17]-'0'!=b[sum]) ans[flag++]=id; } } if(flag==0){ printf("All passed\n"); } else{ for(int i=0;i<flag;i++){ printf("%s\n",s[ans[i]]); } } return 0; }
L1-017 到底有多二 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; char s[50]; int main(){ scanf("%s",s); int len=strlen(s); int n=len,cnt=0; double tmp=1.0; if(s[0]=='-'){ n--; tmp=1.5; } for(int i=0;i<len;i++){ if(s[i]-'0'==2) cnt++; } int flag=1; if((s[len-1]-'0')%2==0) flag=2; double ans=(double)cnt/(double)n*tmp*flag*100; printf("%.2f%%\n",ans); return 0; }
L1-018 大笨鍾 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805119944605696
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int hh,mm; int main(){ scanf("%d:%d",&hh,&mm); if(hh>=0 && hh<=12) printf("Only %02d:%02d. Too early to Dang.\n",hh,mm); else{ if(mm==0){ for(int i=1;i<=hh-12;i++){ printf("Dang"); } printf("\n"); } else{ for(int i=1;i<=hh-12+1;i++){ printf("Dang"); } printf("\n"); } } return 0; }
L1-019 誰先倒 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805118568873984
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=110; int a,b,n; int x[maxn],y[maxn],xx[maxn],yy[maxn]; int main(){ scanf("%d%d",&a,&b); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d%d%d",&x[i],&xx[i],&y[i],&yy[i]); } int suma=0,sumb=0; for(int i=1;i<=n;i++){ if(x[i]+y[i]==xx[i] && x[i]+y[i]!=yy[i]){ suma++; if(suma>a) break; } if(x[i]+y[i]==yy[i] && x[i]+y[i]!=xx[i]){ sumb++; if(sumb>b) break; } } if(suma>a) printf("A\n%d\n",sumb); if(sumb>b) printf("B\n%d\n",suma); return 0; }
L1-020 帥到沒朋友 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805117167976448
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e6+10; int n,m,k,x,b; int vis[maxn]; int main(){ while(~scanf("%d",&n)){ memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ scanf("%d",&k); for(int j=1;j<=k;j++){ scanf("%d",&x); if(k==1) break; vis[x]=1; } } scanf("%d",&m); int cnt=0; for(int i=1;i<=m;i++){ scanf("%d",&b); if(vis[b]==0){ if(++cnt>1) printf(" "); printf("%05d",b); vis[b]=1; } } if(cnt==0) printf("No one is handsome"); printf("\n"); } return 0; }
L1-021 重要的話說三遍 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805115792244736
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!\n"); return 0; }
L1-022 奇偶分家 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805114445873152
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,x; int main(){ scanf("%d",&n); int sum1=0,sum2=0; for(int i=1;i<=n;i++){ scanf("%d",&x); if(x%2==1) sum1++; else sum2++; } printf("%d %d\n",sum1,sum2); return 0; }
L1-023 輸出GPLT (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805113036587008
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e5+10; int cnt[5]; char s[maxn]; int main(){ scanf("%s",s); memset(cnt,0,sizeof(cnt)); int len=strlen(s); for(int i=0;i<len;i++){ if(s[i]=='G' || s[i]=='g') cnt[1]++; if(s[i]=='P' || s[i]=='p') cnt[2]++; if(s[i]=='L' || s[i]=='l') cnt[3]++; if(s[i]=='T' || s[i]=='t') cnt[4]++; } // printf("%d %d %d %d\n",cnt[1],cnt[2],cnt[3],cnt[4]); int tmp=max(cnt[1],max(cnt[2],max(cnt[3],cnt[4]))); for(int i=1;i<=tmp;i++){ if(cnt[1]>0){ printf("G"); cnt[1]--; } if(cnt[2]>0){ printf("P"); cnt[2]--; } if(cnt[3]>0){ printf("L"); cnt[3]--; } if(cnt[4]>0){ printf("T"); cnt[4]--; } } printf("\n"); return 0; }
L1-024 后天 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805111694409728
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); n=n+2; if(n>7) n=n%7; printf("%d\n",n); return 0; }
L1-025 正整數A+B (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805110318678016
思路:需要判斷各種不符合的輸入 包括小於1和大於一千的數據
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e5+10; char a[maxn]; string b; int main(){ scanf("%s ",a); getline(cin,b); int lena=strlen(a),lenb=b.length(); int flaga=0,flagb=0; for(int i=0;i<lena;i++){ if(a[i]-'0'<0 || a[i]-'0'>9) flaga=1; } for(int i=0;i<lenb;i++){ if(b[i]-'0'<0 || b[i]-'0'>9) flagb=1; } int tmpa=0,tmpb=0,tmp=0; if(flaga==0 && flagb==0){ for(int i=0;i<lena;i++){ tmpa=tmpa*10+(a[i]-'0'); } for(int i=0;i<lenb;i++){ tmpb=tmpb*10+(b[i]-'0'); } if(tmpa<1 || tmpa>1000) flaga=1; if(tmpb<1 || tmpb>1000) flagb=1; if(flaga==0 && flagb==0) tmp=tmpa+tmpb; } if(flaga==0 && flagb==0){ printf("%s + ",a); cout<<b; printf(" = %d\n",tmp); } else if(flaga==1 && flagb==0){ printf("? + "); cout<<b; printf(" = ?\n"); } else if(flaga==0 && flagb==1){ printf("%s + ? = ?\n",a); } else if(flaga==1 && flagb==1){ printf("? + ? = ?\n"); } return 0; }
L1-026 I Love GPLT (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805108934557696
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n"); return 0; }
L1-027 出租 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805107638517760
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; char s[20]; int vis[120],arr[120],kk[120]; int main(){ scanf("%s",s); int len=strlen(s); for(int i=0;i<len;i++){ vis[s[i]-'0']=1; } int cnt=0; for(int i=9;i>=0;i--){ if(vis[i]==1) arr[cnt++]=i; } for(int i=0;i<len;i++){ for(int j=0;j<cnt;j++){ if((s[i]-'0')==arr[j]) kk[i]=j; } } printf("int[] arr = new int[]{"); for(int i=0;i<cnt-1;i++){ printf("%d,",arr[i]); } printf("%d};\n",arr[cnt-1]); printf("int[] index = new int[]{"); for(int i=0;i<len-1;i++){ printf("%d,",kk[i]); } printf("%d};\n",kk[len-1]); return 0; }
L1-028 判斷素數 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805106325700608
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,x; int main(){ scanf("%d",&n); while(n--){ scanf("%d",&x); int flag=0; for(int i=2;i<=sqrt(x);i++){ if(x%i==0){ flag=1; break; } } if(x==1) printf("No\n"); else if(x==2) printf("Yes\n"); else if(flag==1) printf("No\n"); else if(flag==0) printf("Yes\n"); } return 0; }
L1-029 是不是太胖了 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805104983523328
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); double m=((double)n-100)*0.9*2; printf("%.1f\n",m); return 0; }
L1-030 一幫一 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805103557459968
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=55; int n; int vis[maxn],id[maxn]; char s[maxn][15]; struct node{ string s1,s2; }kk[maxn]; int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %s",&id[i],s[i]); } int cnt=0; for(int i=0;i<n;i++){ for(int j=n-1;j>=0;j--){ if(id[i]!=id[j] && vis[i]==0 && vis[j]==0){ printf("%s %s\n",s[i],s[j]); vis[i]=1;vis[j]=1; } } } return 0; }
L1-031 到底是不是太胖了 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805102173339648
代碼:

#include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,x,y; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&x,&y); int m=(x-100)*1.8; //printf("%d\n",m); if(abs(m-y)<(m*0.1)) printf("You are wan mei!\n"); if(abs(m-y)>=(m*0.1) && y<m) printf("You are tai shou le!\n"); if(abs(m-y)>=(m*0.1) && y>m) printf("You are tai pang le!\n"); } return 0; }
L1-032 Left-pad (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=101000; int n; char x,s[maxn]; int main(){ scanf("%d %c",&n,&x); getchar(); cin.get(s,101000); int len=strlen(s); if(len>=n){ for(int i=len-n;i<len;i++){ cout<<s[i]; } cout<<endl; } else{ for(int i=0;i<n-len;i++){ cout<<x; } cout<<s<<endl; } return 0; }
L1-033 出生年 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805099426070528
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int x,k; int main(){ scanf("%d%d",&x,&k); int flag=0; for(int i=x;i<=5000;i++){ int cnt=1; int a=i/1000; int b=i%1000/100; int c=i%100/10; int d=i%10; if(a!=b && a!=c && a!=d) cnt++; if(b!=c && b!=d) cnt++; if(c!=d) cnt++; if(cnt==k){ flag=i; break; } } printf("%d %04d\n",flag-x,flag); return 0; }
L1-034 點贊 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805098188750848
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e5+10; int n,k,x; int ans[maxn]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&k); for(int j=1;j<=k;j++){ scanf("%d",&x); ans[x]++; } } int mmax=-1,pos=-1; for(int i=1;i<=1000;i++){ if(ans[i]>=mmax){ mmax=ans[i]; pos=i; } } printf("%d %d\n",pos,mmax); return 0; }
L1-035 情人節 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805097018540032
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e5+10; string s[maxn]; int main(){ int cnt=0; while(cin>>s[++cnt] && s[cnt][0]!='.'); if(cnt>=15){ cout<<s[2]<<" and "<<s[14]; printf(" are inviting you to dinner...\n"); } else if(cnt>=3 && cnt<15){ cout<<s[2]; printf(" is the only one for you...\n"); } else if(cnt<=2) printf("Momo... No one is for you ...\n"); return 0; }
L1-036 A乘以B (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805095676362752
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,m; int main(){ scanf("%d%d",&n,&m); printf("%d\n",n*m); return 0; }
L1-037 A除以B (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805094485180416
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,m; int main(){ scanf("%d%d",&n,&m); if(m==0){ printf("%d/%d=Error\n",n,m); return 0; } double ans=(double)n/(double)m; printf("%d/",n); if(m<0) printf("(%d)",m); else printf("%d",m); printf("=%.2f\n",ans); return 0; }
L1-038 新世界 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805093038145536
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("Hello World\nHello New World\n"); return 0; }
L1-039 古風排版 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805091888906240
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int n; char s[maxn],ans[maxn][maxn]; int main(){ scanf("%d\n",&n); cin.getline(s,1010); int len=strlen(s); int tmp=len/n+(len%n==0?0:1); int cnt=0; for(int i=0;i<tmp;i++){ for(int j=0;j<n;j++){ if(cnt<len) ans[i][j]=s[cnt++]; else ans[i][j]=' '; } } for(int j=0;j<n;j++){ for(int i=tmp-1;i>=0;i--){ putchar(ans[i][j]); } putchar('\n'); } return 0; }
L1-040 最佳情侶身高差 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805090748055552
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int t;double n;char op[2]; int main(){ scanf("%d",&t); for(int i=1;i<=t;i++){ scanf("%s %lf",op,&n); if(op[0]=='M'){ double ans=n/1.09; printf("%.2f\n",ans); } if(op[0]=='F'){ double ans=n*1.09; printf("%.2f\n",ans); } } return 0; }
L1-041 尋找250 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805089657536512
代碼:

#include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int x; int main(){ int cnt=0,vis=0; while(scanf("%d",&x)!=EOF){ cnt++; if(x==250 && vis==0){ printf("%d\n",cnt); vis=1; } } return 0; }
L1-042 日期格式化 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805088529268736
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int m,d,y; int main(){ scanf("%d-%d-%d",&m,&d,&y); printf("%d-%02d-%02d\n",y,m,d); return 0; }
L1-043 閱覽室 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805087447138304
思路:注意一些只有S或只有E的操作
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1010; int n,id,h,m; int ans[maxn],vis[maxn]; char op[2]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ int cnt=0; double sum=0; id=-1; memset(vis,0,sizeof(vis)); while(id!=0){ scanf("%d %s %d:%d",&id,op,&h,&m); if(id==0) break; if(op[0]=='S'){ ans[id]=h*60+m; vis[id]=1; } if(op[0]=='E'){ if(vis[id]==1){ sum+=h*60+m-ans[id]; ans[id]=0; vis[id]=0; cnt++; } } } if(cnt!=0) sum/=cnt; sum+=0.5f; printf("%d %d\n",cnt,(int)sum); } return 0; }
L1-044 穩贏 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805086365007872
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int k;char s[10]; int main(){ scanf("%d",&k); int cnt=0; k++; while(scanf("%s",s)!=EOF && s[0]!='E'){ cnt++; if(s[0]=='C' && cnt%k!=0) printf("Bu\n"); if(s[0]=='C' && cnt%k==0) printf("ChuiZi\n"); if(s[0]=='J' && cnt%k!=0) printf("ChuiZi\n"); if(s[0]=='J' && cnt%k==0) printf("JianDao\n"); if(s[0]=='B' && cnt%k!=0) printf("JianDao\n"); if(s[0]=='B' && cnt%k==0) printf("Bu\n"); } return 0; }
L1-045 宇宙無敵大招呼 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805085295460352
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; char s[15]; int main(){ scanf("%s",s); printf("Hello %s\n",s); return 0; }
L1-046 整除光棍 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805084284633088
思路:模擬豎式除法
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n; int main(){ scanf("%d",&n); int x=1,cnt=1; while(x<n){ x=x*10+1; cnt++; } while(x!=0){ printf("%d",x/n); x=x%n; if(x==0) break; x=x*10+1; cnt++; } printf(" %d\n",cnt); return 0; }
L1-047 裝睡 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805083282194432
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int n,x,y; char s[15]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s%d%d",s,&x,&y); if(x<15 || x>20 || y<50 || y>70) printf("%s\n",s); } return 0; }
L1-048 矩陣A乘以B (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805082313310208
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=110; int r1,r2,c1,c2; int ans1[maxn][maxn],ans2[maxn][maxn],ans[maxn][maxn]; int main(){ scanf("%d%d",&r1,&c1); for(int i=1;i<=r1;i++){ for(int j=1;j<=c1;j++){ scanf("%d",&ans1[i][j]); } } scanf("%d%d",&r2,&c2); for(int i=1;i<=r2;i++){ for(int j=1;j<=c2;j++){ scanf("%d",&ans2[i][j]); } } if(r2!=c1){ printf("Error: %d != %d\n",c1,r2); return 0; } memset(ans,0,sizeof(ans)); for(int i=1;i<=r1;i++){ for(int j=1;j<=c2;j++){ for(int k=1;k<=c1;k++){ ans[i][j]+=ans1[i][k]*ans2[k][j]; } } } printf("%d %d\n",r1,c2); for(int i=1;i<=r1;i++){ for(int j=1;j<c2;j++){ printf("%d ",ans[i][j]); } printf("%d\n",ans[i][c2]); } return 0; }
L1-049 天梯賽座位分配 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805081289900032
思路:最開始要把所有位置都初始化為-1 這樣在只有一個學校的情況下不會出錯
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1100; int n,cnt[maxn],vis[maxn]; struct node{ int res; int ans[maxn]; }kk[maxn]; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ scanf("%d",&kk[i].res); sum+=kk[i].res; } sum*=10; int tmp=n; for(int i=1;i<=n;i++) kk[i].ans[0]=-1; memset(cnt,0,sizeof(cnt)); memset(vis,0,sizeof(vis)); for(int i=1;i<=sum;){ for(int j=1;j<=n;j++){ if(vis[j]==1) continue; if(tmp==1){ kk[j].ans[++cnt[j]]=max(kk[j].ans[cnt[j]-1]+2,i); i++; } else kk[j].ans[++cnt[j]]=i++; if(cnt[j]/10==kk[j].res && cnt[j]%10==0){ vis[j]=1;tmp--; } } } for(int i=1;i<=n;i++){ printf("#%d\n",i); for(int j=1;j<=10*kk[i].res;j++){ printf("%d",kk[i].ans[j]); if(j%10==0) printf("\n"); else printf(" "); } } return 0; }
L1-050 倒數第N個字符串 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805080346181632
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const char s[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; const int maxn=1e5+10; int n,k; char ans[10]={'z'}; int main(){ scanf("%d%d",&n,&k); int a,b=k; for(int i=1;i<=n;i++){ a=b%26; b=k/26; k=b; if(i==1){ if(a==0){ ans[n-i]=s[0]; b--; } else ans[n-i]=s[26-a]; } else ans[n-i]=s[26-a-1]; } printf("%s\n",ans); return 0; }
L1-051 打折 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805079364714496
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; double x,y; int main(){ scanf("%lf%lf",&x,&y); printf("%.2f\n",x/10*y); return 0; }
L1-052 2018我們要贏 (5 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805078400024576
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int main(){ printf("2018\nwo3 men2 yao4 ying2 !\n"); return 0; }
L1-053 電子汪 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805077443723264
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int a,b; int main(){ scanf("%d%d",&a,&b); int m=a+b; for(int i=1;i<=m;i++){ printf("Wang!"); } printf("\n"); return 0; }
L1-054 福到了 (15 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805076512587776
思路:注意空格和換行 用getchar()讀掉換行符 用geline來整行讀入(同時讀入空格)
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=110; int n,vis[maxn][maxn]; char x; string mp[maxn]; int main(){ scanf("%c %d",&x,&n); getchar(); for(int i=0;i<n;i++){ getline(cin,mp[i]); for(int j=0;j<n;j++){ if(mp[i][j]==' ') vis[i][j]=0; else vis[i][j]=1; } } int flag=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(vis[i][j]!=vis[n-i-1][n-j-1]) flag=1; } } if(flag==0){ printf("bu yong dao le\n"); } for(int i=n-1;i>=0;i--){ for(int j=n-1;j>=0;j--){ if(vis[i][j]==0) cout<<" "; else if(vis[i][j]==1) cout<<x; } cout<<endl; } return 0; }
L1-055 誰是贏家 (10 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805075543703552
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; int a,b,ansa,ansb,x; int main(){ scanf("%d%d",&a,&b); ansa=0,ansb=0; for(int i=1;i<=3;i++){ scanf("%d",&x); if(x==0) ansa++; else ansb++; } if(a>b && ansa>=1) printf("The winner is a: %d + %d\n",a,ansa); else if(a<b && ansa==3) printf("The winner is a: %d + %d\n",a,ansa); else printf("The winner is b: %d + %d\n",b,ansb); return 0; }
L1-056 猜數字 (20 分)
鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805074646122496
代碼:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int maxn=1e4+10; int n,x[maxn]; char s[maxn][20]; int main(){ scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++){ scanf("%s %d",s[i],&x[i]); sum+=x[i]; } sum/=(n*2); int minn=inf,pos=0; for(int i=1;i<=n;i++){ if(abs(sum-x[i])<minn){ minn=abs(sum-x[i]); pos=i; } } printf("%d %s\n",sum,s[pos]); return 0; }