这题目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. uvaLA4255 Guess BFS+拓扑排序

    算法指南白书 思路:“连续和转化成前缀和之差” #include <stdio.h> #include <string.h> #include <iostream> ...

  2. Bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 最短路,神题

    3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 218  Solved: ...

  3. [LeetCode] 76. Minimum Window Substring 解题思路

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  4. 一个好看的Input样式

    <div class="search"> <input type="text"></div> .search{ text-a ...

  5. php 写一个水仙花数的函数

    判断一个数是不是水仙花数 <?php function is_shuixianhua($i) { $length=strlen($i); $i=(string)$i; $sum=0; for($ ...

  6. Spring boot 内存优化

    转自:https://dzone.com/articles/spring-boot-memory-performance It has sometimes been suggested that Sp ...

  7. centos防火墙操作

    centos防火墙基本操作 #/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT#/sbin/iptables -I INPUT -p tcp -- ...

  8. gdb调试运行时的程序小技巧

    使用gdb调试运行时的程序小技巧 标签: 未分类 gdb pstack | 发表时间:2012-10-15 04:32 | 作者:士豪 分享到: 出处:http://rdc.taobao.com/bl ...

  9. PHP内核探索之变量(1)变量的容器-Zval

    http://blog.csdn.net/ohmygirl/article/details/41542445

  10. careercup-栈与队列 3.6

    3.6 编写程序,按升序对栈进行排序(即最大元素位于栈顶).最多只能使用一个额外的栈存放临时数据,但不得将元素复制到别的数据结构中(如数组).该栈支持如下操作:push.pop.peek和isEmpt ...