Above Average

Above Average

时间: 1ms        内存:128M

描述:

It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check.

The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 <= N <= 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class. For each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places.

输入:

输出:

示例输入:

5
5 50 50 70 80 100
7 100 95 90 80 70 60 50
3 70 90 80
3 70 90 81
9 100 99 98 97 96 95 94 93 91

示例输出:

40.000%
57.143%
33.333%
66.667%
55.556%

提示:

参考答案(内存最优[752]):

#include <stdio.h>
#include <string.h>

char *x[] = {
"WET","0",
"UTC","0",
"GMT","0",
"BST","+1",
"IST","+1",
"WEST","+1",
"CET","+1",
"CEST","+2",
"EET","+2",
"EEST","+3",
"MSK","+3",
"MSD","+4",
"AST","-4",
"ADT","-3",
"NST","-3.5",
"NDT","-2.5",
"EST","-5",
"EDT","-4",
"CST","-6",
"CDT","-5",
"MST","-7",
"MDT","-6",
"PST","-8",
"PDT","-7",
"HST","-10",
"AKST","-9",
"AKDT","-8",
"AEST","+10",
"AEDT","+11",
"ACST","+9.5",
"ACDT","+10.5",
"AWST","+8",
"",""};

int i,j,k,h,m,n,N,time;
char buf[100];
double off;

main(){
   scanf("%d",&N);
   while (N--) {
      scanf(" %s",buf);
      if (!strcmp(buf,"noon")) time = 12*60;
      else if (!strcmp(buf,"midnight")) time = 0;
      else {
         sscanf(buf,"%d:%d",&h,&m);
         if (h == 12) h = 0;
         time = h*60 + m;
         scanf(" %s",buf);
         if (!strcmp(buf,"p.m.")) time += 12*60;
      }
      scanf(" %s",buf);
      for (i=0;*x[i] && strcmp(x[i],buf);i++);
      if (strcmp(x[i],buf)) printf("oops:  <<<%s>>>\n",buf);
      sscanf(x[i+1],"%lf",&off);
      time -= 60 * off; 
      scanf(" %s",buf);
      for (i=0;*x[i] && strcmp(x[i],buf);i++);
      if (strcmp(x[i],buf)) printf("oops:  %s\n",buf);
      sscanf(x[i+1],"%lf",&off);
      time += 60 * off; 
      time = (time + 24*60) % (24*60);
      if (time == 0) printf("midnight\n");
      else if (time == 12 * 60) printf("noon\n");
      else {
         h = time/60%12;
         if (h == 0) h = 12;
         m = time%60;
         printf("%d:%02d %s\n",h,m,time>12*60?"p.m.":"a.m.");
      }
   }
}

参考答案(时间最优[0]):

#include <stdio.h>
#include <string.h>

char *x[] = {
"WET","0",
"UTC","0",
"GMT","0",
"BST","+1",
"IST","+1",
"WEST","+1",
"CET","+1",
"CEST","+2",
"EET","+2",
"EEST","+3",
"MSK","+3",
"MSD","+4",
"AST","-4",
"ADT","-3",
"NST","-3.5",
"NDT","-2.5",
"EST","-5",
"EDT","-4",
"CST","-6",
"CDT","-5",
"MST","-7",
"MDT","-6",
"PST","-8",
"PDT","-7",
"HST","-10",
"AKST","-9",
"AKDT","-8",
"AEST","+10",
"AEDT","+11",
"ACST","+9.5",
"ACDT","+10.5",
"AWST","+8",
"",""};

int i,j,k,h,m,n,N,time;
char buf[100];
double off;

main(){
   scanf("%d",&N);
   while (N--) {
      scanf(" %s",buf);
      if (!strcmp(buf,"noon")) time = 12*60;
      else if (!strcmp(buf,"midnight")) time = 0;
      else {
         sscanf(buf,"%d:%d",&h,&m);
         if (h == 12) h = 0;
         time = h*60 + m;
         scanf(" %s",buf);
         if (!strcmp(buf,"p.m.")) time += 12*60;
      }
      scanf(" %s",buf);
      for (i=0;*x[i] && strcmp(x[i],buf);i++);
      if (strcmp(x[i],buf)) printf("oops:  <<<%s>>>\n",buf);
      sscanf(x[i+1],"%lf",&off);
      time -= 60 * off; 
      scanf(" %s",buf);
      for (i=0;*x[i] && strcmp(x[i],buf);i++);
      if (strcmp(x[i],buf)) printf("oops:  %s\n",buf);
      sscanf(x[i+1],"%lf",&off);
      time += 60 * off; 
      time = (time + 24*60) % (24*60);
      if (time == 0) printf("midnight\n");
      else if (time == 12 * 60) printf("noon\n");
      else {
         h = time/60%12;
         if (h == 0) h = 12;
         m = time%60;
         printf("%d:%02d %s\n",h,m,time>12*60?"p.m.":"a.m.");
      }
   }
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注