7-24 帅到没朋友
没注意要%05d 错了很久 其他很快打完
#include <bits/stdc++.h> using namespace std; int main() { map<int,int>ma; int n;cin>>n; for(int i=1;i<=n;i++ ) { int k;cin>>k; if(k==1){int x;cin>>x;continue;} while(k--) { int x;cin>>x; ma[x]=1; } } int k;cin>>k; int first=1; while(k--) { int x;cin>>x; if(ma[x]!=1&&first){first=0;printf("%05d",x);ma[x]=1;} else if(ma[x]!=1&&first==0) {printf(" %05d",x);ma[x]=1;} } if(first)printf("No one is handsome"); return 0; }
7-27 输出GPLT
非常水的20分
#include <bits/stdc++.h> using namespace std; int a[200]={0}; int main() { string s; getline(cin,s); for(int i=0;i<s.size();i++) { if(s[i]=='G'||s[i]=='g')a['G']++; if(s[i]=='P'||s[i]=='p')a['P']++; if(s[i]=='L'||s[i]=='l')a['L']++; if(s[i]=='T'||s[i]=='t')a['T']++; } int f=1; while(f) { f=0; if(a['G']>0){f=1;a['G']--;printf("%c",'G');} if(a['P']>0){f=1;a['P']--;printf("%c",'P');} if(a['L']>0){f=1;a['L']--;printf("%c",'L');} if(a['T']>0){f=1;a['T']--;printf("%c",'T');} } return 0; }
7-29 抢红包
主要是一个结构体的排序 1 bool cmp(struct ren a,struct ren b) 其中return a.s>b.s; 而不是 return a>b;
2 sort(a+1,a+1+n,cmp); 排序1到n 必须要加一
#include <bits/stdc++.h> using namespace std; struct ren { int t; int num; double s; }a[10005]; bool cmp(struct ren a,struct ren b) { if(a.s!=b.s)return a.s>b.s; else if(a.num!=b.num)return a.num>b.num; else return b.t>a.t; } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { a[i].t=i; int k;cin>>k; for(int j=1;j<=k;j++) { int n1,x; cin>>n1>>x; a[i].s-=x; a[n1].s+=x; a[n1].num++; } } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { cout<<a[i].t<<" "; printf("%.2lf",a[i].s/100); cout<<endl; } return 0; }
7-30 排座位
并查集简单问题
#include<iostream> #include<cstring> #include <bits/stdc++.h> using namespace std; int b[105]={0}; int a[105][105]={0}; int find1(int x); void uni(int x,int y); int main(){ for(int i=1;i<=100;i++) b[i]=i; int n,k,q; cin>>n>>k>>q; for(int i=1;i<=k;i++) { int a1,a2,a3; cin>>a1>>a2>>a3; a[a1][a2]=a[a2][a1]=a3; if(a3==1) uni(a1,a2); } for(int i=1;i<=q;i++) { int x,y;cin>>x>>y; if(a[x][y]==1){printf("No problem\n");continue;} if(a[x][y]==0){printf("OK\n");continue;} if(a[x][y]==-1&&find1(x)==find1(y)){printf("OK but...\n");continue;} if(a[x][y]==-1&&find1(x)!=find1(y))printf("No way\n"); } return 0; } int find1(int x) { int j=x; while(b[j]!=j) j=b[j]; int i=x; while(i!=j) { int t=b[i]; b[i]=j; i=t; } return j; } void uni(int x,int y) { int x1=find1(x); int y1=find1(y); if(x1!=y1) b[x1]=y1; }