日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Kattis-What does the fox say 字符串处理+STL

發(fā)布時間:2025/4/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kattis-What does the fox say 字符串处理+STL 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目

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 T. 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 goes . 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 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?Sample Output 1 wa pa pa pa pa pa pow

思路

使用vector把第一行叫聲存入 再用set標(biāo)記出來每個animal的叫聲,然后判斷是否出現(xiàn)即可。
問題在于字符串的處理。

第一。
While(cin>>temp)可以連續(xù)輸入
退出的條件是:1.無效輸入,比如類型不同;2.遇到文件結(jié)束符(End_Of_FIle)。

第二。出現(xiàn)第一個goes作為第一行截止標(biāo)記。然后刪除goes前面的那個元素即可。

讀入第一行叫聲的代碼實現(xiàn)

while(cin>>temp){//輸入第一行 if(temp=="goes")//后面肯定有一個輸入,第一個叫聲 {cin>>temp;s.insert(temp);//存進(jìn)來v.pop_back();//goes之前有個無用的字符,刪除 break;}v.push_back(temp);//進(jìn)入向量 }

代碼

#include<bits/stdc++.h>using namespace std;int main() {int t;cin>>t;getchar();while(t--){vector<string> v;//存入第一行的叫聲 set<string> s;//標(biāo)記下面的叫聲 string temp;while(cin>>temp){//輸入第一行 if(temp=="goes")//后面肯定有一個輸入,第一個叫聲 {cin>>temp;s.insert(temp);//存進(jìn)來v.pop_back();//goes之前有個無用的字符,刪除 break;}v.push_back(temp);//進(jìn)入向量 }string animal,sound;//讀取animal goes sound while(cin>>animal>>temp>>sound){if(temp!="goes")//最有一句輸入沒用,有五個字符,全部吃掉{cin>>temp>>animal;break; }s.insert(sound);//sound 進(jìn)入set用作判斷 }for(size_t i=0;i<v.size();++i){if(s.find(v[i])==s.end())//在s中沒有找到則是fox 的叫聲 {cout<<v[i];if(i==v.size()-1) cout<<endl;else cout<<" ";}}}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Kattis-What does the fox say 字符串处理+STL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。