hdu2093
这一题其实不难,要注意输出和 ‘-’ 的次数以及排序,未用qsort的时候一直超时,晕死了!!!
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 struct infor{ 6 char name[11]; 7 int count,time; 8 }people[1000]; 9 10 int m; 11 12 int cmp( const void *a,const void *b ){ 13 struct infor *c =( struct infor * )a; 14 struct infor *d =( struct infor * )b; 15 if( c ->count != d ->count )return d ->count - c ->count; 16 else if( c->time != d -> time )return c -> time - d -> time; 17 else return c -> name - d -> name; 18 } 19 20 int main() 21 { 22 int deal( char p[] ); 23 int n, i, j, k; 24 char p[100]; 25 26 memset( people, 0, sizeof( people ) ); 27 28 scanf( "%d%d", &n, &m ); 29 30 k = 0; 31 while(scanf("%s",people[k].name)!=EOF){ 32 for( j = 0; j < n; j ++ ){ 33 scanf( "%s", p ); 34 if( deal( p ) > 0 ){ 35 people[k].count ++; 36 people[k].time += deal( p ); 37 } 38 } 39 k ++; 40 } 41 42 qsort( people, k, sizeof( people[0] ), cmp ); 43 44 for( i = 0; i < k; i ++ ){ 45 printf( "%-10s %2d %4d\n", people[i].name, people[i].count, people[i].time); 46 } 47 return 0; 48 } 49 int deal( char p[] ){ 50 int i, j, lenth, wrong, time, t; 51 52 if( p[0] == '-' ) 53 return 0; 54 55 for( i = 0; p[i] != '(' && p[i] != '\0'; i ++ ); 56 57 lenth = strlen( p ); 58 wrong = time = 0; 59 for( j = i - 1, t = 1; j >= 0; j -- ){ 60 time += ( p[j] - '0' ) * t; 61 t *= 10; 62 } 63 if( p[lenth-1] == ')' ){ 64 for( i = lenth - 2, t = 1; p[i] != '('; i -- ){ 65 wrong += ( p[i] - '0' ) * t; 66 t *= 10; 67 } 68 time += wrong * m; 69 } 70 71 return time; 72 }

浙公网安备 33010602011771号