题目:

 

Determined to discover the ancient mystery—the sound that the fox makes—you went into the forest, armed with a very good digital audio recorder. The forest is, however, full of animals’ voices, and on your recording, many different sounds can be heard. But you are well prepared for your task: you know exactly all the sounds which other animals make. Therefore the rest of the recording—all the unidentified noises—must have been made by the fox.

Input

The first line of input contains the number of test cases TT. The descriptions of the test cases follow:

The first line of each test case contains the recording—words over lower case English alphabet, separated by spaces. Each contains at most 100 letters and there are no more than 100 words. The next few lines are your pre-gathered information about other animals, in the format <animal> goes <sound>. There are no more than 100 animals, their names are not longer than 100 letters each and are actual names of animals in English. There is no fox goes ... among these lines.

The last line of the test case is exactly the question you are supposed to answer: what does the fox say?

Output

For each test case, output one line containing the sounds made by the fox, in the order from the recording. You may assume that the fox was not silent (contrary to popular belief, foxes do not communicate by Morse code).

Sample Input 1 Sample Output 1
1
toot woof wa ow ow ow pa blub blub pa toot pa blub pa pa ow pow toot
dog goes woof
fish goes blub
elephant goes toot
seal goes ow
what does the fox say?
wa pa pa pa pa pa pow

题解:

难度不大,就是如果用C写的话,处理字符串时很烦,细节要搞好。

把其他动物的叫声放到一个队列里,对于那堆叫声,如果不能在队列里找到,则证明是狼的叫声,直接输出。

C代码如下:

 #include<cstdio>//E - E Kattis - whatdoesthefoxsay
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<set> using namespace std; typedef long long ll; char s[],a[];
char voice[];
char m[][]; int main()
{
int t,vsum,len,cnt;
scanf("%d",&t);
getchar();
while(t--)
{
vsum = ;
gets(s);//读取动物的叫声
while()
{
gets(a);
if(!strcmp(a,"what does the fox say?")) break; len = strlen(a);
cnt = ;
for(int i = len-; a[i]!=' '; i--)//倒着读取动物声音,跳过无用信息
voice[cnt++] = a[i];
voice[cnt] = ; char tmp;//处理动物声音
len = strlen(voice);
for(int i = ; i<=(len-)/; i++)//把动物声音调回正序
{
tmp = voice[i]; voice[i] = voice[len--i]; voice[len--i] = tmp;
} strcpy(m[vsum],voice);//将非狼声音放到队列中
vsum++;
} cnt = ;
s[strlen(s)] = ' ';
s[strlen(s)] = ;
for(int i = ; s[i]!=; i++)
{
if(s[i]==' ')
{
voice[cnt] = ;
cnt = ; int j;
for(j = ; j<vsum; j++)
if(strcmp(voice,m[j])==) break; if(j==vsum)
printf("%s ",voice);
} else
voice[cnt++] = s[i];
}
putchar('\n');
} return ;
}

C++代码如下(使用STL则简便多了):

 #include<iostream>//E - E Kattis - whatdoesthefoxsay
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<set>
#include<string>
#include<set>
#define LL long long
using namespace std; char a[],s[];//C语言开250可以过,为什么C++就不行了?而要开2500
set<string>m;
string voice; int main()
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
gets(s);
m.clear();
while()
{
gets(a);
if(!strcmp(a,"what does the fox say?")) break; voice = "";
for(int i = strlen(a)-; a[i]!=' '; i--)//倒着读取动物声音,跳过无用信息
voice += a[i]; char tmp;
for(int i = ,len = voice.size(); i<=(len-)/; i++)//把动物声音调回正序
{
tmp = voice[i]; voice[i] = voice[len--i]; voice[len--i] = tmp;
} m.insert(voice);
} s[strlen(s)] = ' ';
s[strlen(s)] = ;
voice = "";
for(int i = ,len = strlen(s); i<len; i++)
{
if(s[i]==' ')
{
if(m.find(voice)==m.end())
cout<<voice<<' ';
voice = "";
} else
voice += s[i];
}
putchar('\n');
}
return ;
}

Kattis - whatdoesthefoxsay —— 字符串的更多相关文章

  1. Kattis - virus【字符串】

    Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...

  2. Kattis - names Palindrome Names 【字符串】

    题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使 ...

  3. Kattis - prva 【字符串】

    题意 从上到下 或者 从左到右 组成的长度 >= 2 的字符串 如果遇到 # 就断掉 输出 字典序最小的那一个 思路 只要从上到下 和从左到右 分别遍历一遍,将 长度 >= 2 的字符串 ...

  4. Kattis - yoda 【字符串】

    分析 给出两个串 从末尾开始对齐 每位对齐后,每一位 遍历 如果 第一串 的那位 < 第二串 的 那么 第一串的那位 就删去 如果 等于 两位 都保留 如果 大于 那么 保留 第二串的 那位 如 ...

  5. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  6. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  7. 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率

    之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...

  8. java中的字符串相关知识整理

    字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...

  9. JavaScript 字符串实用常操纪要

    JavaScript 字符串用于存储和处理文本.因此在编写 JS 代码之时她总如影随形,在你处理用户的输入数据的时候,在读取或设置 DOM 对象的属性时,在操作 Cookie 时,在转换各种不同 Da ...

随机推荐

  1. Ext grid单元格编辑时获取获取Ext.grid.column.Column

    item2.width = 80; //item2.flex = 1; item2.align = 'center'; item2.menuDisabled = true; //禁止显示列头部右侧菜单 ...

  2. The Process class relies on proc_open, which is not available on your PHP installation

    [Symfony\Component\Process\Exception\RuntimeException] The Process class relies on proc_open, which ...

  3. [UIDevice currentDevice]

    获取iphone的系统信息使用[UIDevice currentDevice],信息例如以下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone O ...

  4. Utuntu 和 window共享文件

    由于自己想用服务器跑代码,数据集和模型一般都在本机电脑上,用实验室服务器需要拷贝数据或者,在服务器上重新下载数据很麻烦 都在局域网内可以实现文件共享,代码和数据都在本地,共享给服务器,只需要使用服务器 ...

  5. 网络通讯框架MINA和XSCOCKET的简单比较

    http://www.blogjava.net/ghostdog/archive/2008/06/10/MinaVsXsocket.html实在无聊,考虑把当前应用的通讯模式由http移植为socke ...

  6. PC常用电源IC、MOS、三极管、二极管厂家

    笔记本常用MOS.三极管.二极管厂家: 1.EMC 杰力电子(台湾)官方网站:http://www.excelliancemos.com/tw/solution.php 2.UBIQ(台湾电源厂家UP ...

  7. Something about cache

    http://www.tyut.edu.cn/kecheng1/2008/site04/courseware/chapter5/5.5.htm 5.5 高速缓冲存储器cache 随着CPU时钟速率的不 ...

  8. Spring Cloud(十):服务网关zuul(转)

    前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...

  9. Windows 10遭遇百万粉丝“围攻”(挑刺)

    9月30日,微软公布Win 10技术预览版,征求反馈意见. 出人意料的是.截止10月14日.在短短两周内,竟有百万粉丝下载试用(所谓"測试"),反馈了20万条改动意见.对此,微软真 ...

  10. python--简易员工信息系统编写

    补充内容:eval 将字符串变成变量名locals   看输入的是否是字典中的一个keyfunc.__name____怎么看变量名的数据类型斐波那契数列 li=[1,1] while li[-1]&l ...