|
Posted on 2010-08-19 01:45 Kevin_Zhang 阅读(158) 评论(0) 编辑 收藏 引用 所属分类: 模拟
#include "iostream"
#include "string"
#include "ctype.h"
#include "algorithm"
#include "Map"
using namespace std;
char a[34][9]={".-","-","-.-.","-..",".","..-.","--.",".","..",".---","-.-",".-..",
"--","-.","---",".--.","--.-",".-.","","-","..-","-",".--","-..-","-.--","--..","..--",".-.-","---.","----"};
int b[34]={2,4,4,3,1,4,3,4,2,4,3,4,2,2,3,4,4,3,3,1,3,4,3,4,4,4,4,4,4,4};
int main()
{
int m,n;
int i;
int count=0;
int num[800],num2[800];
char word[1900];
char ch;
map<string, char> mapcode;
for(i=0;i<26;i++)
{
ch='A'+i;
mapcode.insert(pair<string, char>(a[i],ch));
}
ch='_';
mapcode.insert(pair<string, char>(a[26],ch));
ch=',';
mapcode.insert(pair<string, char>(a[27],ch));
ch='.';
mapcode.insert(pair<string, char>(a[28],ch));
ch='?';
mapcode.insert(pair<string, char>(a[29],ch));
int nSize = mapcode.size();
/**//*for(i= 0,ch='A'; i < nSize; i++)
{
cout<<mapcode[a[i]]<<" "<<a[i]<<" "<<b[i]<<endl;
}*/
cin>>n;
getchar();
while(n--)
{
count++;
i=0;
memset(num,0,sizeof(num));
memset(num2,0,sizeof(num2));
string temp("");
while(1)
{
ch=getchar();
if(ch=='\n') break;
if(ch=='_')
{
temp=temp+a[26];
num[i]=b[26];
}
else if(ch==',')
{
temp=temp+a[27];
num[i]=b[27];
}
else if(ch=='.')
{
temp=temp+a[28];
num[i]=b[28];
}
else if(ch=='?')
{
temp=temp+a[29];
num[i]=b[29];
}
else if(isalpha(ch))
{temp=temp+a[ch-'A'];
num[i]=b[ch-'A'];}
i++;
}
int len=i-1;
for(i=0;i<=len;i++)
{
num2[i]=num[len-i];
}
// cout<<num2<<endl;
//cout<<temp<<endl;
int k=0;
cout<<count<<": ";
for(i= 0;i<=len; i++)
{
cout<<mapcode[temp.substr(k,num2[i])];
k=k+num2[i];
}
cout<<endl;
}
}
|