华为oj中级 数据分类处理
2017-03-29 14:36
274 查看
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<unordered_map> #include<fstream> #include<sstream> #include<queue> #include<stack> #include<map> #include<unordered_map> #include<utility> #include<iomanip> using namespace std; int main() { int num_I; int num_R; while (cin >> num_I){ vector<string> I(num_I); for (int i = 0; i < num_I; i++) cin >> I[i]; cin >> num_R; vector<int> R(num_R); for (int i = 0; i < num_R; i++) cin >> R[i]; //调整R; sort(R.begin(), R.end()); vector<int>::iterator it = unique(R.begin(), R.end()); R.erase(it, R.end()); vector<int> pos; vector<int> cnt; vector<bool> Flag; bool flag = false; string str; for (int i = 0; i < R.size(); i++){ int cnt_tem = 0; for (int j = 0; j < I.size(); j++){ str = to_string(R[i]); if (I[j].find(str) != string::npos){ cnt_tem++; pos.push_back(j); } } if (cnt_tem != 0){ cnt.push_back(cnt_tem); flag = true; Flag.push_back(flag); }else{ flag = false; Flag.push_back(flag); } } int NUM = cnt.size()*2 + pos.size()*2; cout << NUM << " "; vector<int> r; for (int i = 0; i < R.size(); i++){ if (Flag[i]){ r.push_back(R[i]); } } int tem = 0; int i = 0; for (; i < r.size(); i++){ cout << r[i] << " " << cnt[i] << " "; for (int j = tem + 0; j < cnt[i] + tem; j++){ if (j == pos.size() - 1){ cout << pos[j] << " " << I[pos[j]] << endl; break; } cout << pos[j] << " " << I[pos[j]] << " "; } tem += cnt[i]; } } return 0; }
相关文章推荐
- [华为OJ] 数据分类处理
- 华为OJ数据分类处理
- 【华为OJ】【091-数据分类处理】
- 华为OJ_数据分类处理
- 华为机试---数据分类处理
- 华为oj中级 字符串合并处理
- 华为机试在线训练-牛客网(15)数据分类处理
- 华为OJ中级题-识别有效的IP地址和掩码并进行分类统计
- 华为oj中级 识别有效的IP地址和掩码并进行分类统计
- 《华为机试在线训练》之数据分类处理
- 华为在线编程系列-数据分类处理
- 华为OJ 中级 字符串合并处理
- 华为OJ中级题-字符串合并处理
- php处理行业分类数据
- 华为 OJ 初级 输入一个int型数据,计算出该int型数据在内存中存储时1的个数。
- 总结数据挖掘预测分类中的样本筛选和特征处理
- 【华为OJ】求int型数据在内存中存储时1的个数
- 数据清洗小记:分类进行字符串转日期(某日期字段存在多类格式处理)
- 第十二周 项目二:OJ平台中多种输入形式的处理(2)输入多组数据,直到文件尾
- 华为oj 字符串合并处理