您的位置:首页 > 其它

华为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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: