这题目WA了好几次,主要是我没有理解清楚No solution.这个情况。

如果在match原文做好了,基本map一下就能过了。

与原句match的条件就是:

1.出现了26个字母

2.该空格的地方要空格,不该空格的地方不要空格

3.该相同的地方相同,不该相同的地方不相同。

~真的是好久不做PC题目,输入输出都不习惯了~弄得好郁闷。

/*******************************************************************************/
/* OS : 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 UTC 2013 GNU/Linux
* Compiler : g++ (GCC) 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
* Encoding : UTF8
* Date : 2014-03-30
* All Rights Reserved by yaolong.
*****************************************************************************/
/* Description: ***************************************************************
*****************************************************************************/
/* Analysis: ******************************************************************
*****************************************************************************/
/*****************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
string KN="the quick brown fox jumps over the lazy dog";
int lenKN=KN.length();
char p[27];
bool isMatch(string s)
{
int i,j;
if(s[3]!=' '||s[9]!=' '||s[15]!=' '||s[ 19]!=' '||s[25]!=' '|| s[30]!=' '||s[34]!=' '||s[39]!=' ')
return 0; memset(p,0,sizeof(27));
for(i=0;i<s.length();i++){
if(s[i]!=' ')
p[s[i]-'a']++;
}
int res=0;
for(i=0;i<26;i++){
if(p[i]) res++;
}
if(res!=26) return 0;
for(i=0;i<lenKN;i++){
for(j=0;j<lenKN;j++){
if(KN[i]==KN[j]&&s[i]!=s[j]){
return 0;
}
if(KN[i]!=KN[j]&&s[i]==s[j]){
return 0;
} }
} return 1; }
int main()
{ int cases,i,j;
vector<string> str;
string tmp;
map<char,char> mp;
cin>>cases;
getchar();
getchar();
int first=1;
while(cases--)
{ if(first) first=0;
else cout<<endl; mp.clear();
str.clear(); while(getline(cin,tmp)&&tmp.length())
{
str.push_back(tmp);
}
int siz=str.size(); int flag=0;
for(i=0; i<siz; i++)
{ if(str[i].length()==lenKN&&isMatch(str[i]))
{
flag=1; for(j=0; j<lenKN; j++)
{
mp[str[i][j]]=KN[j];
} }
} if(flag)
{
for(i=0; i<siz; i++)
{
for(j=0; j<str[i].length(); j++)
cout<<mp[str[i][j]]; cout<<endl; }
}
else cout<<"No solution.\n"; } return 0; }

PC110304/UVA850的更多相关文章

  1. UVA850【简单模拟】

    题目:解密句子.有一些被加密的句子已知一条模板翻译,判断是否可以解密,可以的话将所有句子解密. #include <stdio.h> #include<iostream> #i ...

随机推荐

  1. glsl-BufferObject- change

    修改其值的最快方式: 创建: Mutable Storage To create mutable storage for a buffer object, you use this API: void ...

  2. Python初始值表示为无穷大

    之前只知道设置变量的初始值为0.今天在写网络路径分析的时候,为了找到离任意坐标距离最近的节点,初始设置最短距离为无穷大,然后不断的去替换,直到找到最近的节点. 刚开始设置是min_dis = 9999 ...

  3. 关于理解《C++ 对象模型》中:把单一元素的数组放在末尾,struct可以拥有可变大小的数组

    这一章在第19页,写的好深奥,我竟然没看明白在说什么--之后再看了几遍,终于明白了. 原文: C程序员的巧计有时候却成为c++程序员的陷阱.例如把单一元素的数组放在一个struct的末尾,于是每个st ...

  4. HW4.27

    public class Solution { public static void main(String[] args) { int count = 0; for(int i = 2001; i ...

  5. ReactiveCocoa框架学习1

    写block直接使用inline block的声明类型 在ARC中使用strong,如果不使用strong,则会被销毁 在非ARC中使用copy block在开发中的使用场景 把block保存到对象中 ...

  6. linux 创建连接命令 ln -s 软连接

    这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s, 具体用法是:ln -s 源文件 目标文件. 当 我们需要在不同 ...

  7. apache启动目录(禁止目录)与设置默认入口文件的方法

    设置默认入口文件的方法: 打开apache的conf目录,找到httpd.conf文件,打开这个文件,搜索dir_module,找到以下截图修改位置进行修改,注意重启apache服务器,修改位置才会生 ...

  8. 推荐一个可以直接在Visual Studio中看到complexity的插件CodeMaid

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:推荐一个可以直接在Visual Studio中看到complexity的插件CodeMaid.

  9. Sending e-mail with Spring MVC---reference

    reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...

  10. 编写跨平台代码之memory alignment

    编写网络包(存储在堆上)转换程序时,在hp-ux机器上运行时会遇到 si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer ...