标签:aci class 题意 模拟题 pac its temp region while
题意略。
思路:
这种字符串的模拟题,应该熟练使用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; }
2013-2014 ACM-ICPC Pacific Northwest Regional Contest L.Languages
标签:aci class 题意 模拟题 pac its temp region while
原文地址:https://www.cnblogs.com/tiberius/p/9382148.html