BNU Online Judge-34776-What does the fox say?

本文介绍了一道趣味编程题目——“狐狸的叫声”,通过去除已知动物叫声来找出狐狸的叫声。利用C++实现,涉及字符串处理、哈希表等技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

http://www.bnuoj.com/bnuoj/problem_show.php?pid=34776

题意: fox 的叫声  

例如测试用例

输入

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

这样理解就是其他动物没有叫过的声音就是fox叫的例如把toot woof wa ow ow ow pa blub blub pa toot pa blub pa pa ow pow toot 中woof   blub   toot  ow

去掉就是答案。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
map<string,int>M;
int main()
{
int t;
scanf("%d",&t);
char s1[11000];
char ss[150];
char sss[110][110];
map<char,int>::iterator it;
while(t--)
{
getchar();
gets(s1);
int k=0;
M.clear();
memset(sss,'\0',sizeof(sss));
while(scanf("%s",ss)&&strcmp(ss,"say?")!=0)
{
k++;
if(k%3==0)
{
M[ss]=1;
}
}
//it=M.end();
//printf("%d\n",M.size());
//it=M.find("the");
M.erase(M.end(),M.end());
int len=strlen(s1);
int ans=0;
for(int i=0; i<len; i++)
{
if(s1[i]==' ')
{
ans++;
continue;
}
char d[10];
d[0]=s1[i];
d[1]='\0';
strcat(sss[ans],d);
}
int flag=0;
for(int i=0; i<=ans; i++)
{
if(!M[sss[i]])
{
if(flag==0)
{
printf("%s",sss[i]);
flag++;
}
else
printf(" %s",sss[i]);
}
}
printf("\n");
}
return 0;
}

转载于:https://www.cnblogs.com/liudehao/p/4008606.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值