- #include<stdio.h>
- #include<string.h>
- #include<ctype.h>
- #define MAX 1100
- char in[MAX] , check[MAX][200] , *str , word[MAX] ;
- char *reserve[32] = { "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while" } ;
- int i , j , check_length = -1 , sort[MAX] , line = 0 , number[MAX][200] = {0} ;
- void getword() ;
- int search() ;
- int main()
- {
- while( gets( in ) )
- {
- line++ ;
- for( i = 0 ; in[i] ; i++ )
- if( isalpha( in[i] ) || in[i] == '_' )
- {
- getword() ;
- if( search() )
- {
- check_length++ ;
- strcpy( check[ check_length ] , word ) ;
- number[ check_length ][ 0 ] = 1 ;
- number[ check_length ][ 1 ] = line ;
- }
- }
- }
- for( i = 0 ; i<=check_length ; i++ )
- sort[ i ] = i ;
- for( i = 0 ; i<check_length ; i++ )
- for( j = i+1 ; j<=check_length ; j++ )
- if( strcmp( check[ (sort[j]) ] , check[ (sort[i]) ] ) < 0 )
- sort[ i ] ^= sort[ j ] ^= sort[ i ] ^= sort[ j ] ;
- for( i = 0 ; i<=check_length ; i++ )
- {
- printf( "%s:" , &check[ sort[i] ] ) ;
- for( j = 1 ; j <= number[ sort[i] ][ 0 ] ; j++ )
- printf( " %d" , number[ sort[i] ][j] ) ;
- putchar( '\n' ) ;
- }
- scanf( " " ) ;
- }
- void getword()
- {
- int tmp_length = 1 ;
- word[ 0 ] = in[ i ] ;
- for( ++i ; isalnum( in[ i ] ) || in[i] == '_' ; tmp_length++ , i++ )
- word[ tmp_length ] = in[ i ] ;
- i-- ;
- word[ tmp_length ] = '\0' ;
- }
- int search()
- {
- for( j = 0 ; j<32 ; j++ )
- if( !strcmp( word , reserve[j] ) )
- return 0 ;
- for( j = 0 ; j <= check_length ; j++ )
- {
- if( !strcmp( word , check[ j ] ) )
- {
- if( number[ j ][ number[ j ][ 0 ] ] == line )
- return 0 ;
- ++number[ j ][ 0 ] ;
- number[ j ][ number[ j ][ 0 ] ] = line ;
- return 0 ;
- }
- }
- return 1 ;
- }
Raw Paste