当前位置:文档之家› 北京大学计算概论医学部罗英伟模拟考试答案

北京大学计算概论医学部罗英伟模拟考试答案

北京大学计算概论(医学部)-罗英伟模拟考试答案二1#include <stdio.h>int main(){int n,i,a=0,b=0,c=0;scanf("%d",&n);for (i=1; i<=n; i++){int a1,b1,c1;scanf("%d%d%d",&a1,&b1,&c1);a+=a1; b+=b1; c+=c1;}printf("%d %d %d %d\n",a,b,c,a+b+c);return 0;} 2.#include <stdio.h>int main(){int n,i,a=0,b=0,c=0,d=0;scanf("%d",&n);for (i=1; i<=n; i++){int t;scanf("%d",&t);if (t<=18) a++;else if (t<=35) b++;else if (t<=60) c++;else d++;}int s=a+b+c+d;printf("1-18: %.2lf%%\n",(double)a/s*100); printf("19-35: %.2lf%%\n",(double)b/s*100); printf("36-60: %.2lf%%\n",(double)c/s*100); printf("60以上: %.2lf%%\n",(double)d/s*100);return 0;} 3.#include <stdio.h>int main(){int s,i;scanf("%d",&s);int money[6]={100,50,20,10,5,1};for (i=0; i<6; i++){printf("%d\n",s/money[i]);s=s%money[i];}return 0;} 4.、#include <stdio.h>int main(){int m,n;scanf("%d%d",&m,&n); double s=0,h=m;int i;for (i=1; i<=n; i++){s+=h+h/2;h=h/2;}printf("%lf,%lf",s,h);return 0;}5.#include <stdio.h>int main(){int n,k;int a[1000];scanf("%d%d",&n,&k);int i,j;for (i=0; i<n; i++) scanf("%d",&a[i]);int p=0;for (i=0; i<n-1; i++){for (j=i+1; j<n; j++)if (a[i]+a[j]==k) {p=1; break;}if (p==1) break;}if (p==1) printf("yes\n"); else printf("no\n"); return 0;}6.#include <stdio.h>int main(){int n,k;int a[1000];scanf("%d%d",&n,&k);int i,j;for (i=0; i<n; i++) scanf("%d",&a[i]);int p=0;for (i=0; i<n-1; i++){for (j=i+1; j<n; j++)if (a[i]+a[j]==k) {p=1; break;}if (p==1) break;}if (p==1) printf("yes\n"); else printf("no\n"); return 0;} 7.#include <stdio.h>struct info{char ID[11];int age;}old[100],young[100];int main(){int n,i;scanf("%d",&n);struct info t;int Nold=0,Nyoung=0;for (i=1; i<=n; i++){scanf("%s%d",t.ID,&t.age); if (t.age>=60){Nold++;old[Nold-1]=t;}else{Nyoung++;young[Nyoung-1]=t;}}int j;for (i=1; i<=Nold-1; i++)for (j=0; j<Nold-i; j++)if (old[j].age<old[j+1].age){t=old[j];old[j]=old[j+1];old[j+1]=t;}for (i=0; i<Nold; i++) printf("%s\n",old[i].ID);for (i=0; i<Nyoung; i++) printf("%s\n",young[i].ID);return 0;}8.#include <stdio.h>struct info{char ID[11];int age;}old[100],young[100];int main(){int n,i;scanf("%d",&n);struct info t;int Nold=0,Nyoung=0;for (i=1; i<=n; i++){scanf("%s%d",t.ID,&t.age); if (t.age>=60){Nold++;old[Nold-1]=t;}else{Nyoung++;young[Nyoung-1]=t;}}int j;for (i=1; i<=Nold-1; i++)for (j=0; j<Nold-i; j++)if (old[j].age<old[j+1].age){t=old[j];old[j]=old[j+1];old[j+1]=t;for (i=0; i<Nold; i++) printf("%s\n",old[i].ID);for (i=0; i<Nyoung; i++) printf("%s\n",young[i].ID);return 0;}9.#include <stdio.h>int main(){int n,i,j;scanf("%d",&n);double ld[100];for (i=0; i<n;i++) scanf("%lf",&ld[i]); int a[100];for (i=0; i<n; i++) a[i]=1;for (i=n-2; i>=0; i--)int max=0;for (j=i+1; j<n; j++)if (ld[i]>=ld[j] && a[j]>max) max=a[j]; a[i]=max+1;}int max=0;for (i=0; i<n; i++) if (a[i]>max) max=a[i];printf("%d",max);return 0;}。

相关主题