View Code
#include " iostream " #include " math.h " using namespace std; int main(){ char ch[ 101 ]; int a[ 1000 ]; int b[ 100 ]; int i,j; while ( 1 ) { int s = 0 ; while (gets(ch)) { if (strcmp(ch, " * " ) == 0 ) break ; if (strcmp(ch, " # " ) == 0 ) break ; int L = strlen(ch); int k = 0 ; for (i = 0 ;i < strlen(ch);i ++ ) { if (ch[i] == ' ' ) k ++ ; if (ch[i] != ' ' ) { if (k) { if (k % 2 == 0 ) a[s] = 1 ; else a[s] = 0 ; s ++ ; k = 0 ; } } } } if (strcmp(ch, " # " ) == 0 ) break ; while (s % 5 != 0 ) { a[s ++ ] = 0 ; } for (i = 0 ;i < s / 5 ;i ++ ) { int sum = 0 ; for (j = 5 * i + 4 ;j >= 5 * i;j -- ) { sum += a[j] * pow( 2 , 5 * i + 4 - j); } b[i] = sum; } for (i = 0 ;i < s / 5 ;i ++ ) { if (b[i] >= 1 && b[i] <= 26 ) printf( " %c " , b[i] + 64 ); else { if (b[i] == 0 ) printf( " " );//容易忽略的地方 if (b[i] == 27 ) printf( " ' " ); if (b[i] == 28 ) printf( " , " ); if (b[i] == 29 ) printf( " - " ); if (b[i] == 30 ) printf( " . " ); if (b[i] == 31 ) printf( " ? " ); } } cout << endl; } return 0 ;}