團隊賽(第十週)
阿新 • • 發佈:2018-11-11
A
3 E right
10 A wrong
30 C wrong
50 B wrong
100 A wrong
200 A right
250 C wrong
300 D right
-1
7 H right
15 B wrong
30 E wrong
35 E right
80 B wrong
80 B right
100 D wrong
100 C wrong
300 C right
300 D wrong
-1
Sample Output
3 543
4 502
題意:計算罰時,輸出AC題個數和罰時。
思路:這個題AC了就將時間加起來,要是前面有WR了,一次20分鐘。
#include <iostream> #include<cstdio> #include<cstring> #include<map> #include<algorithm> #include<math.h> #include<queue> #include <set> using namespace std; typedef long long ll; priority_queue<int> q; set <char> s; int main() { ll ans=0,i,j,m,sum=0,n; char a,b[10]; ll flag[500]={0},c[500]={0}; while(cin>>n) { if(n==-1) { cout<<ans<<" "<<sum<<endl; memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(flag,0,sizeof(flag)); sum=0;ans=0; continue; } cin>>a>>b; if(flag[a-'A']==0&&strcmp(b,"right")==0) { sum+=c[a-'A']+n; flag[a-'A']=1; ans++; } else if(flag[a-'A']==0) { c[a-'A']+=20; } } return 0; }
F
Sample Input
5
JOE
BOB
ANDY
AL
ADAM
11
HOPE
ALI
BECKY
JULIE
MEGHAN
LAUREN
MORGAN
CARLI
MEGAN
ALEX
TOBIN
4
GEORGE
JOHN
PAUL
RINGO
Sample Output
DECREASING
NEITHER
INCREASING
題意:字串是升序排列,輸出INCREASING,降序DECREASING,否則NEITHER。
思路:直接sort,比較就好。
#include <iostream> #include<cstdio> #include<cstring> #include<map> #include<algorithm> #include<cmath> #include<queue> #include <set> #include <map> #include <vector> using namespace std; typedef long long ll; priority_queue<int> q; set <char> s; bool cmp(char *a,char *b) { return strcmp(a,b)<0; } int main() { ll n; while(cin>>n) { char s[100][100]; char *p[100]; ll i,j; for(i=0; i<n; i++) { cin>>s[i]; p[i]=s[i]; } sort(p,p+n,cmp); if(strcmp(p[0],s[0])==0) { ll ans=0; for(i=1; i<n; i++) { if(strcmp(p[i],s[i])==0) ans++; } if(ans==n-1) cout<<"INCREASING"<<endl; else cout<<"NEITHER"<<endl; } else if(strcmp(p[n-1],s[0])==0) { ll ans=0; for(i=1,j=n-2; i<n,j>=0; i++,j--) { if(strcmp(p[j],s[i])==0) ans++; } if(ans==n-1) cout<<"DECREASING"<<endl; else cout<<"NEITHER"<<endl; } else cout<<"NEITHER"<<endl; } return 0; }
D
Sample Input
ABC HAPPYBIRTHDAYCACEY
ABC TRAGICBIRTHDAYCACEY
ABC HAPPYBIRTHDAY
SECRET SOMECHORESARETOUGH
SECRET SOMECHEERSARETOUGH
Sample Output
PASS
FAIL
FAIL
PASS
FAIL
題意:第一個串依次在第二個出現過,不能提前出現。
思路:將長串作為主串,比較兩個串的當前位置,相等j++,不是就繼續走(此時i++了),然後看小串的j位置是否在主串中出現過,出現直接跳出。
#include <iostream> #include<cstdio> #include<cstring> #include<map> #include<algorithm> #include<math.h> #include<queue> #include <set> using namespace std; typedef long long ll; priority_queue<int> q; set <char> s; int main() { char a[10],b[100],c[100]; ll flag[100]={0}; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(flag,0,sizeof(flag)); while(cin>>a>>b) { ll i,j,k; ll n=strlen(b); ll nn=strlen(a); j=0; for(i=0;i<n;i++) { if(b[i]==a[j]) j++; else { for(k=j;k<nn;k++) if(b[i]==a[k]) break; if(k<nn) break; } } if(i==n&&j==nn) cout<<"PASS"<<endl; else cout<<"FAIL"<<endl; } return 0; }