uva 10785

#include <iostream> #include <cstring> using namespace std ; const int maxn = 300 ;//数组开太大以致tle好多次呀!!! char str1[maxn] , str2[maxn] ; char vow[] = { 'A' , 'U' , 'E' , 'O' , 'I' } ; char con[] = { 'J' , 'S' , 'B' , 'K' , 'T' , 'C' , 'L' , 'D' , 'M' , 'V' , 'N' , 'W' , 'F' , 'X' , 'G' , 'P' , 'Y' , 'H' , 'Q' , 'Z' , 'R' } ; int count1[200] ; int cmp( const void * _a , const void * _b ) { char * a = ( char * ) _a ; char * b = ( char * ) _b ; return * a - * b ; } int val( char i ) { switch( i ) { case 'A' : case 'J' : case 'S' : return 1 ; case 'B' : case 'K' : case 'T' : return 2 ; case 'C' : case 'L' : case 'U' : return 3 ; case 'D' : case 'M' : case 'V' : return 4 ; case 'E' : case 'N' : case 'W' : return 5 ; case 'F' : case 'O' : case 'X' : return 6 ; case 'G' : case 'P' : case 'Y' : return 7 ; case 'H' : case 'Q' : case 'Z' : return 8 ; case 'I' : case 'R' : return 9 ; } } void get1( char s[] , int cur ) { for( int i = 0 ; i < 5 ; i++ ) { if( val( vow[i] ) >= val( s[cur-2] ) && count1[vow[i]] < 21 ) { count1[vow[i]]++ ; s[cur] = vow[i] ; break ; } } return ; } void get2( char s[] , int cur ) { for( int i = 0 ; i < 21 ; i++ ) { if( val( con[i] ) >= val( s[cur-2] ) && count1[con[i]] < 5 ) { count1[con[i]]++ ; s[cur] = con[i] ; break ; } } return ; } void build( int len ) { memset( count1 , 0 , sizeof( count1 ) ) ; memset( str1 , 0 , sizeof( str1 ) ) ; memset( str2 , 0 , sizeof( str2 ) ) ; int s1 = 0 ; int s2 = 0 ; for( int i = 0 ; i < len ; i++ ) if( !( i % 2 ) ) get1( str1 , s1++ ) ; else get2( str2 , s2++ ) ; qsort( str1 , s1 , sizeof( char ) , cmp ) ; qsort( str2 , s2 , sizeof( char ) , cmp ) ; return ; } int main() { int icase = 1 ; int ncase = 0 ; cin >> ncase ; while( ncase-- ) { int len = 0 ; cin >> len ; cout << "Case " << icase++ << ": " ; int ap = 0 , bp = 0 ; int a , b; build( len ) ; for( int i = 0 ; i < len ; i++ ) { if( !( i % 2 ) ) cout << str1[ap++] ; else cout << str2[bp++] ; } cout << endl ; } return 0 ; }

你可能感兴趣的:(uva 10785)