PC110304/UVA850
这题目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的更多相关文章
- UVA850【简单模拟】
题目:解密句子.有一些被加密的句子已知一条模板翻译,判断是否可以解密,可以的话将所有句子解密. #include <stdio.h> #include<iostream> #i ...
随机推荐
- Linux学习笔记31——网络信息
一 主机数据库函数 #include <netdb.h> struct hostent *gethostbyaddr(const void *addr, //地址 size_t len, ...
- Poj 2299 - Ultra-QuickSort 离散化,树状数组,逆序对
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 52306 Accepted: 19194 ...
- Bzoj 1227: [SDOI2009]虔诚的墓主人 树状数组,离散化,组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 895 Solved: 422[Submit][Statu ...
- html背景为灰色 不能操作,中间div可以操作
<container style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; z-index: ...
- 关于一次Weblogic活动线程的问题处理
Weblogic控制台监控发现 环境>>服务器>>你的服务器>>监控>>线程 中活动执行线程竟然是2000多.同一套系统在另一套平台上,并且访问的人不少 ...
- String和StringBuilder作为参数的区别
先见下面实例: public class TestDemo { @Test public void test(){ //String str = "hello"; String s ...
- linux系统垃圾清理
早上刚来,服务器出502错误了.我登上linux服务器,发现敲一个命令都提示没空间了, 用 df -h 查看了下 发现系统盘目录空间大小占用达到90%多,我觉得有些诧异, 难道是产生系统垃圾 然后用 ...
- (转)在javascript中关于submit和button提交表单区别
原文来自:http://www.jb51.net/article/42236.htm submit是button的一个特例,也是button的一种,它把提交这个动作自动集成了,submit和b ...
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据--转载
原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/ Zookeeper 分布式服务框架是 Apache Hadoop ...
- Grant-Permission.ps1
Grant-Permission.ps1 Download the EXE version of SetACL 3.0.6 for 32-bit and 64-bit Windows. Put set ...