uva-850-Crypt Kicker II

/*
 * =====================================================================================
 *
 *       Filename:  y.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2011¿?10¿?29¿? 12¿?59¿?36¿?
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include<iostream>
#include<ctype.h>
#include<map>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<memory.h>
#include<cstring>


using namespace std;


string s= "the quick brown fox jumps over the lazy dog";
int a[110];//由明文到密文
int b[110];//由密文到明文
int flag;//记录是否存在一个转换


bool isfind(string& dest)
{
for( int i=0; i<110 ; i++ )
{
a[i]=30;
b[i]=30;
}


for(int  i=0; i<dest.size() ; i++ )
{
if( s[i]==' '&&dest[i]!=' ' )
{
//cout<<"e1"<<endl;
return false;
}
if( s[i]!=' '&&dest[i]==' ' )
{
//cout<<"e2"<<endl;
return false;
}
if( s[i]==' '&&dest[i]==' ' )
{
continue;
}
if( dest[i]<'a'||dest[i]>'z' )
{
//cout<<"e3"<<endl;
return false;
}
//cout<< a[s[i]-'a']<<endl;
if( a[s[i]-'a']==30&&b[dest[i]-'a']==30 )
{
//cout<<"ok"<<endl;


a[s[i]-'a']=dest[i]-'a';
b[dest[i]-'a']=s[i]-'a';
}
if( (a[s[i]-'a']==(dest[i]-'a'))&&(b[dest[i]-'a']==(s[i]-'a')) )
{
continue;
}
else
{
//cout<<"e4"<<endl;
return false;
}
}
return true;
}
int main(int argc, char *argv[])
{
int cs;


cin>>cs;
getchar();
getchar();
while( cs-- )
{
string str[110];
int i=0;
flag=0;
while( true )
{
getline(cin,str[i],'\n');
if( str[i]=="" )
{
break;
}
else
{
if( str[i].size()==s.size()&&flag!=1 )
{
bool tmp=isfind(str[i]);
if( tmp )
{
flag=1;
}
}
i++;
}
}


if( flag==0 )
{
cout<<"No solution."<<endl;


}
else
{
for( int j=0; j<i ; j++ )
{
for( int k=0; k<str[j].size() ; k++ )
{
if(isspace( str[j][k]) )
{
cout<<" ";
}
else
{
cout<<(char)(b[str[j][k]-'a']+'a');
}
}
cout<<endl;
}
}
if(cs>=1 )
{
cout<<endl;
}
}
return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值