先贴个代码吧,晚点在写解题报告....
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string.h>
#include<math.h>
int bit[2000];
int i=0,k=0,tip=0,y=0,m,q;
int fristc=0,coust[2000];
char c,mima[2000];
void BIT (char)
{
if(c==' ')
{
if(fristc ==1 || tip==1)
i++;
bit[i]=!bit[i];
fristc=0;
}
else
fristc=1;
}
void SHOW ()
{
int ge=0;
for( int i=0; i<=m; i++)
{
if(coust[i]>=1&&coust[i]<=26)mima[ge]=coust[i]-1+'A';
if(coust[i]==0)mima[ge]=' ';
if(coust[i]==27)mima[ge]='\'';
if(coust[i]==28)mima[ge]=',';
if(coust[i]==29)mima[ge]='-';
if(coust[i]==30)mima[ge]='.';
if(coust[i]==31)mima[ge]='?';
ge++;
}
ge-=1;
int i=0;
while(mima[i]==' ')i++;
while(mima[ge]==' ')ge--;
for(; i<=ge; i++)
printf("%c",mima[i]);
}
void CH()
{
if(i%5==0)
m=i/5;
else
m=i/5+1;
for(int g = 1; g <= i; g++)
bit[g]=!bit[g];
for( q =0; q<m; q++)
for ( int p =1; p <=5; p++)
coust[q]+=bit[q*5+p]*pow(2.0,5-p);
SHOW();
}
int main()
{
while((c=getchar())!='#')
{
tip++;
if(c=='*')
{
CH();
printf("\n");
i=0;
fristc=0;
memset(bit,0,sizeof(bit));
memset(coust,0,sizeof(coust));
}
BIT(c);
}
return 0;
}