标签:VID nbsp ret 个数 单词 多次 啊啊啊 algorithm open
#include <iostream> #include <fstream> #include <vector> using namespace std; int main() { vector<string> v; string s; ofstream outfile; outfile.open("Name.txt"); while(cin >> s) { outfile << s << endl; v.push_back(s); if(v.size() > 4) v.erase(v.begin()); int num = 1; for(int i = v.size() - 1; i >= 0; i--) { cout << num++ << "=" << v[i] << " "; outfile << num - 1 << "=" << v[i] << " "; } cout << endl; outfile << endl; } outfile.close(); return 0; }
#include <iostream> #include <vector> #include <map> #include <set> using namespace std; int main() { int n; cin >> n; int arr[n], b[n]; set<int> s; map<int, vector<int> > v; for(int i = 0; i < n; i++) { cin >> arr[i]; s.insert(arr[i]); } for(int i = 0; i < n; i++) { cin >> b[i]; v[b[i]].push_back(arr[i]); } for(int i = 0; i < n; i++) { if(v[b[i]].empty()) continue; map<int, int> mmp; for(int j = 0; j < v[b[i]].size(); j++) { mmp[v[b[i]][j]]++; } cout << b[i] << "={"; int cnt = 0; for(auto k = s.begin(); k != s.end(); k++) { cout << *k << "=" << mmp[*k]; cnt++; if(cnt < s.size()) cout << ","; } cout << "}" << endl; v[b[i]].clear();//防止多次输出,加了此清空操作,也可以前面用flag决定是否输出 } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; map<string, int> mm; bool cmp(string s1, string s2) { return mm[s1] > mm[s2]; } int main() { string s; while (getline(cin, s)) { string str; vector<string> v; for (int i = 0; i < s.length(); i++) { if (s[i] == ‘ ‘ || s[i] == ‘,‘ || s[i] == ‘.‘) { if (str != "") { mm[str]++; v.push_back(str); str = ""; } } else str += tolower(s[i]); } sort(v.begin(), v.end(), cmp); map<string, int> op; for (auto it = v.begin(); it != v.end(); it++) { op[*it]++; if(op[*it] > 1) continue; cout << *it << " " << mm[*it] << endl; } } return 0; }
PS:每次都有不同的烦,慌,加油啊啊啊啊啊啊!!!
标签:VID nbsp ret 个数 单词 多次 啊啊啊 algorithm open
原文地址:https://www.cnblogs.com/ache/p/12543439.html