Posted on 2008-10-26 14:21
Hero 阅读(146)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1644 C++ Accepted 0.015 125 KB URAL
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 const int size = 110 ;
8
9 struct NODE {
10 int num ;
11 int isok ;
12 };
13 struct NODE node[size] ;
14
15 int inn ; char instr[50] ;
16
17 int cmp( const void *a, const void *b )
18 {
19 struct NODE *c = (struct NODE *)a ;
20 struct NODE *d = (struct NODE *)b ;
21
22 if( c->num != d->num ) return c->num - d->num ;
23 else return d->isok - c->isok ;//注意这里要反着来,可能有num相同的情况
24 }
25
26 int main()
27 {
28 while( scanf( "%d", &inn ) != EOF )
29 {
30 for( int i=1; i<=inn; i++ )
31 {
32 scanf( "%d", &node[i].num ) ;
33 scanf( "%s", instr ) ;
34 if( 0 == strcmp( "satisfied", instr ) ) node[i].isok = 1 ;
35 else node[i].isok = 0 ;
36 }
37
38 qsort( node+1, inn, sizeof(node[1]), cmp ) ;
39
40 bool OK = true ; int i ;
41 for( i=1; i<=inn&&0==node[i].isok; i++ ) ;
42 if( i > inn )
43 {
44 printf( "10\n" ) ;
45 }
46 else
47 {
48 for( int j=i; j<=inn; j++ ) if( 0==node[j].isok )
49 {
50 OK = false ; break ;
51 }
52 if( OK )
53 {
54 printf( "%d\n", node[i].num ) ;
55 }
56 else
57 {
58 printf( "Inconsistent\n" ) ;
59 }
60 }
61 }
62
63 return 0 ;
64 }