C++博客 :: 首页 :: 新随笔 ::  ::  :: 管理

pku1051

Posted on 2010-08-19 01:45 Kevin_Zhang 阅读(148) 评论(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
<stringchar> mapcode;

  
for(i=0;i<26;i++)

  
{

      ch
='A'+i;

         mapcode.insert(pair
<stringchar>(a[i],ch));

  }


  ch
='_';

  mapcode.insert(pair
<stringchar>(a[26],ch));

  ch
=',';

  mapcode.insert(pair
<stringchar>(a[27],ch));

    ch
='.';

  mapcode.insert(pair
<stringchar>(a[28],ch));

    ch
='?';

  mapcode.insert(pair
<stringchar>(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;

  }


 

}


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理