uva 10420

来源:互联网 发布:银行家算法的基本思想 编辑:程序博客网 时间:2024/06/15 12:51
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>char temp[1000], input[1000];char word[5000][1000];void change( int i, int j ){char temp[1000];strcpy( temp, word[i] );strcpy( word[i], word[j] );strcpy( word[j], temp );}int main(){int n, time, a, j;scanf( "%d\n", &n );a = 0;while( n-- ){gets( input );for( int i = 0, j = 0; i < strlen(input); i++ ){if( input[i] == ' ' ){strcpy( word[a++], temp );break;}else{temp[j++] = input[i];temp[j] = '\0';}}}for( int i = 0; i < a; i++ ){int flag = 0;int x = strlen(word[i]);int y = strlen(word[i+1]);for( int j = i+1; j < a; j++ ){for( int k = 0; k < x || k < y; k++ ){if(  tolower(word[i][k]) > tolower(word[j][k])  )   {change( i, j );flag = 1;}if( tolower(word[i][k]) < tolower(word[j][k])   ){flag = 1;break;}}if( !flag ){if( x > y )change( i, j );}}}time = 1;for( int i = 0; i < a; i++ ){if( strcmp(word[i], word[i+1]) == 0 ){time++;}else{printf( "%s %d\n", word[i], time );time = 1;}}return 0;}

原创粉丝点击