题目链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/24
就做了几个简单题直接上代码吧~
A题: Assembly Line

1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <stdlib.h> 7 #include <algorithm> 8 using namespace std; 9 char s[1005], s1[1005]; 10 int main( ) 11 { 12 int T; 13 scanf( "%d", &T ); 14 while( T -- ){ 15 scanf( "%s", &s ); 16 strcpy( s1 , s); 17 int l=strlen(s ); 18 sort( s, s+l) ; 19 int ans=0, t=0; 20 for( int i=0, j; i<l; ++ i ){ 21 if( s[i]!= s1[i] ){ 22 for( j=i+1; j<l; ++ j ){ 23 if( s1[j]==s[i] && s[j]==s1[i] ){ 24 ans++; 25 s[j]=s1[j]; 26 break; 27 } 28 } 29 if( j==l ){ 30 t++; 31 } 32 } 33 } 34 ans+=( t/3*2 ); 35 printf( "%d\n", ans ); 36 } 37 return 0; 38 }
B题: Bus

1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <stdlib.h> 7 using namespace std; 8 int N; 9 char s[105]; 10 int a[26]; 11 int main( ) 12 { 13 while( scanf("%d", &N)!= EOF ){ 14 memset( a, 0, sizeof a ); 15 int ans=0; 16 for( int i=0; i<N; ++ i ){ 17 scanf( "%s", s); 18 a[s[0]-'a']++; 19 for( int i=0; i<26; ++ i ){ 20 if(a[i]==2){ 21 ans++; 22 memset(a, 0, sizeof( a ) ); 23 break; 24 } 25 } 26 27 } 28 printf( "%d\n", ans ); 29 } 30 return 0; 31 }
E题: Encode

1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <stdlib.h> 7 using namespace std; 8 int T; 9 char s[10005]; 10 int t[20], n; 11 void fuck( int n, int m) 12 { 13 memset( t, 0, sizeof( t ) ); 14 int i=0; 15 while( n ){ 16 t[i++]=n%2; 17 n/=2; 18 } 19 i=5; 20 while( m ){ 21 t[i++]=m%2; 22 m/=2; 23 } 24 } 25 void fuck2( ) 26 { 27 int ans=0; 28 for( int i=7; i>=0; --i ) 29 ans*=2, ans+=t[i]; 30 printf( "%02x", ans ); 31 } 32 int main( ) 33 { 34 scanf( "%d", &T ); 35 while( T -- ){ 36 scanf( "%s", s ); 37 int l=strlen( s ); 38 for( int i=0; s[i]; ++i){ 39 int n=1; 40 while( s[i+1]&&s[i+1]==s[i] && n<8 ){ 41 i++; n++; 42 puts( s+n ); 43 } 44 fuck( s[i]-'a', n-1 ); 45 fuck2( ); 46 } 47 puts( "" ); 48 } 49 return 0; 50 }