题解 | #数据分类处理#
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
#include <iostream> #include <vector> #include <set> using namespace std; int main() { vector<unsigned int> res; int a, b; cin >> a; vector<unsigned int> vin(a, 0); for (int i = 0; i < a; i++) { cin >> vin[i]; } int n1 = vin.size(); set<unsigned int> rn; cin >> b; for (int i = 0; i < b; i++) { unsigned int tmp; cin >> tmp; rn.insert(tmp); } vector<unsigned int> rin(rn.begin(), rn.end()); int nums = rin.size(); for (int i = 0; i < nums; i++) { // cout << "i:" << i << endl; int loc = 0, num = 0; vector<unsigned int> arr; while (loc < n1) { string tmp = to_string(vin[loc]), tmp1 = to_string(rin[i]); if (tmp.find(tmp1) != string::npos) { arr.push_back(loc); arr.push_back(vin[loc]); num++; } loc++; } // cout << "arr.size()" << arr.size() << endl; if (arr.size() == 0) { continue; } else { arr.insert(arr.begin(), num); arr.insert(arr.begin(), rin[i]); res.insert(res.end(), arr.begin(), arr.end()); } } res.insert(res.begin(), res.size()); for (auto& i : res) { cout << i << " "; } return 0; } // 64 位输出请用 printf("%lld")
注意find函数的返回值判断方法