A 组队比赛
最小和最大一队就行
#include<bits/stdc++.h> using namespace std; int main(){ int a[5]; while(cin>>a[0]>>a[1]>>a[2]>>a[3]){ sort(a,a+4); int b=a[0]+a[3]; int c=a[2]+a[1]; if(b>c) cout<<b-c<<endl; else cout<<c-b<<endl; } return 0; }
B 每日一报
把异常温度的都存起来,按要求排序就行
#include<bits/stdc++.h> using namespace std; struct A{ int t; int num; float te; }a[110]; bool cmp(A b,A c){ if(b.t>c.t)return 1; else if(b.t<c.t)return 0; else{ if(b.te>c.te)return 1; else if(b.te<c.te)return 0; else{ if(b.num>c.num)return 0; else return 1; } } } int main(){ int n; while(cin>>n){ int cnt=0; while(n--){ int b,c; float d; cin>>b>>c>>d; if(d>=38.0){ a[cnt].t=b; a[cnt].num=c; a[cnt].te=d; cnt++; } } cout<<cnt<<endl; sort(a,a+cnt,cmp); for(int i=0;i<cnt;i++){ printf("%d %d %.1f\n",a[i].t,a[i].num,a[i].te); } } return 0; }
C 最长非公共子序列
如果两个字符串相等则是-1,否则为最长字符串的长度
#include<bits/stdc++.h> using namespace std; int main(){ string s1,s2; while(cin>>s1>>s2){ if(s1.size()!=s2.size()){ cout<<max(s1.size(),s2.size())<<endl;; } else if(s1!=s2){ cout<<s1.size()<<endl; } else{ cout<<"-1\n"; } } return 0; }
D 最大字符集
1和2特判,其余都为11,101,1001,10001,100001......
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n){ if(n==1){ cout<<1<<endl<<1<<endl;continue; } if(n==2){ cout<<2<<endl<<0<<endl<<11<<endl;continue; } cout<<n-1<<endl; for(int i=2;i<=n;i++){ for(int j=1;j<=i;j++){ if(j==1||j==i) cout<<"1"; else cout<<"0"; } cout<<endl; } } return 0; }
E 美味的序列
边加边减就行,用long long存答案,顺便一提,全加起来再减应该不行,过不了
#include<bits/stdc++.h> using namespace std; typedef long long ll; bool cmp(int a,int b){return a>b;} int a[100010]; int main(){ int n; while(cin>>n){ for(int i=0;i<n;i++){ scanf("%d",&a[i]); } sort(a,a+n,cmp); ll ans=0,d=0; for(int i=0;i<n;i++,d++){ ans+=a[i]-d; } cout<<ans<<endl; } return 0; }
F 日期小助手
母亲节在8到14之间变动,父亲节在15到21之间变动,注意闰年对日期变动的影响,以及,2100年不是闰年,刚开始在2100卡死也是够了。
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int y,m,d; cin>>y>>m>>d; int mo=14-((y-2000)+(y-2000)/4)%7; int fa=21-((y-1998)+(y-2000)/4+1)%7; if(y==2100){ mo=9;fa=20; } //cout<<mo<<"&&"<<fa<<endl; if(m>=1&&m<=4){ printf("Mother's Day: May %dth, %d\n",mo,y);continue; } if(m==5){ if(d<mo) printf("Mother's Day: May %dth, %d\n",mo,y); else{ if(fa!=21) printf("Father's Day: June %dth, %d\n",fa,y); else printf("Father's Day: June %dst, %d\n",fa,y); } continue; } if(m==6){ if(d<fa){ if(fa!=21) printf("Father's Day: June %dth, %d\n",fa,y); else printf("Father's Day: June %dst, %d\n",fa,y); } else{ if(y==2100) mo=8; else if(y==2099) mo=9; else mo=14-((y+1-2000)+(y+1-2000)/4)%7; printf("Mother's Day: May %dth, %d\n",mo,y+1); } continue; } if(m>=7&&m<=12){ if(y==2100) mo=8; else if(y==2099) mo=9; else mo=14-((y+1-2000)+(y+1-2000)/4)%7; printf("Mother's Day: May %dth, %d\n",mo,y+1); } continue; } return 0; }
前6道水题奉上,剩下的能力不够还没写出来。