题意略。
思路:
这种字符串的模拟题,应该熟练使用stringstream。
详见代码:
#include<bits/stdc++.h> using namespace std; map<string,string> mp; vector<string> store; void change(string& str){ for(int i = 0;i < str.length();++i){ str[i] = tolower(str[i]); } } int main(){ std::ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; string str; getline(cin,str); for(int i = 0;i < n;++i){ getline(cin,str); stringstream ss(str); string name,temp; ss>>name; while(ss>>temp){ change(temp); mp[temp] = name; } } getline(cin,str); while(getline(cin,str)){ for(int i = 0;i < str.length();++i){ if(str[i] == ‘,‘ || str[i] == ‘.‘ || str[i] == ‘!‘ || str[i] == ‘;‘ || str[i] == ‘(‘ || str[i] == ‘)‘ || str[i] == ‘?‘){ str[i] = ‘ ‘; } } stringstream ss(str); store.clear(); string temp; while(ss>>temp){ change(temp); store.push_back(temp); } for(int i = 0;i < store.size();++i){ if(mp.count(store[i])){ cout<<mp[store[i]]<<endl; break; } } } return 0; }
原文地址:https://www.cnblogs.com/tiberius/p/9382148.html
时间: 2024-11-13 08:28:34