PAT 1026 程序运行时间
链接::http://www.patest.cn/contests/pat-b-practise/1026
代码:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int a,b,c,d,f,g; scanf("%d%d",&a,&b); c=b-a; if(c/10%10>=5) c=c/100+1; else c=c/100; d=c/3600; f=c%3600/60; g=c%60; if(d<10) printf("0%d:",d); else printf("%d:",d); if(f<10) printf("0%d:",f); else printf("%d:",f); if(g<10) printf("0%d",g); else printf("%d",g); return 0; }
链接:http://www.patest.cn/contests/pat-b-practise/1027
代码:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { char c; int n,m,high=0,width,r=0; scanf("%d %c",&n,&c); if(n<7) { printf("%c\n%d\n",c,n-1); return 0; } m=n; for(int i=1;;++high,i+=2) { if(i==1) { width=i; m-=width; } else { width=i; m-=(width*2); } if(m<(i+2)*2) { ++high; r=m; break; } } //printf("%d %d\n",width,high); for(int i=0;i<high;++i) { for(int j=0;j<i;++j) printf(" "); for(int j=0;j<width-i*2;++j) printf("%c",c); printf("\n"); } int len=width/2; for(int i=1;i<high;++i) { for(int j=0;j<len-i;++j) printf(" "); for(int j=0;j<i*2+1;++j) printf("%c",c); printf("\n"); } printf("%d\n",r); return 0; }
PAT 1028 人口普查
链接:http://www.patest.cn/contests/pat-b-practise/1028
代码:注意符合条件的人数可能为0
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct person { int y,m,d; string name; } p,oldest,youngest; int st,en; int cal(struct person tmp) { return (tmp.y-1814)*365+tmp.m*30+tmp.d; } bool check() { if(cal(p)<st||cal(p)>en) return false; if(cal(p)>=cal(youngest)) { youngest.name=p.name; youngest.y=p.y; youngest.m=p.m; youngest.d=p.d; } if(cal(p)<=cal(oldest)) { oldest.name=p.name; oldest.y=p.y; oldest.m=p.m; oldest.d=p.d; } return true; } int main() { int n,countx=0; char c[10]; scanf("%d",&n); youngest.y=1814; youngest.m=9; youngest.d=6; oldest.y=2014; oldest.m=9; oldest.d=6; st=9*30+6; en=200*365+9*30+6; for(int i=0; i<n; ++i) { scanf("%s%d/%d/%d",c,&p.y,&p.m,&p.d); p.name=string(c); if(check()) { ++countx; } } if(countx==0) printf("0\n"); else printf("%d %s %s\n",countx,oldest.name.c_str(),youngest.name.c_str()); return 0; }
PAT 1029 旧键盘
链接:http://www.patest.cn/contests/pat-b-practise/1029
代码:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<set> #include<algorithm> using namespace std; set<char> charSet; int main() { bool flag; char s1[100],s2[100]; scanf("%s%s",s1,s2); //printf("%s\n%s\n",s1,s2); int len1=strlen(s1); int len2=strlen(s2); for(int i=0,j=0; i<len1; ++i) { flag=false; if(j==len2) { flag=true; } else { if(s1[i]==s2[j]) ++j; else flag=true; } if(flag) { if('a'<=s1[i]&&s1[i]<='z') s1[i]=s1[i]+'A'-'a'; if((charSet.count(s1[i]))==0) { charSet.insert(s1[i]); printf("%c",s1[i]); } } } printf("\n"); return 0; }
PAT 1030 完美数列
链接:http://www.patest.cn/contests/pat-b-practise/1030
代码:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<set> #include<algorithm> using namespace std; double v[100005]; int main() { int n,maxx=0; double p; scanf("%d%lf",&n,&p); for(int i=0;i<n;++i) scanf("%lf",&v[i]); sort(v,v+n); for(int i=0;i<n; i++) for(int j=i+maxx-1; j<n; j++) { if(v[i]*p<v[j]) break; if(j-i+1>maxx) maxx =j-i+1; } printf("%d\n",maxx); return 0; }