@[TOC]好用的工具
#include<iostream>
#include<vector>
#include<sstream>
#include<cmath>
#include<string>
using namespace std;
string str;
void func(string input){
int str_len = input.length();
vector<vector<int>> a_b_r;
vector<int> tmp;
int tmp_int = 0;
bool flag = false;
for(int i = 0; i<str_len; i++){
// cout << input[i] << endl;
if(input[i] == 'A' || input[i] == 'B' || input[i] == 'R'){
if(0 != tmp.size()){
a_b_r.push_back(tmp);
}
vector<int>().swap(tmp);//清空vector
continue;
}
if('0' <= input[i] && input[i] <= '9'){
tmp_int = tmp_int * 10 + int(input[i] - '0');
flag = true;
}
else if(flag){
tmp.push_back(tmp_int);
tmp_int = 0;
flag = false;
}
}
if(flag == true){
tmp.push_back(tmp_int);
a_b_r.push_back(tmp);
}
int r = a_b_r[2][0];
vector<int> a = a_b_r[0];
vector<int> b = a_b_r[1];
// vector<int
pair<int, int> p;
vector<pair<int, int>> result;
flag = false;
for(int i = 0; i < a.size(); i++){
flag = false;
for(int j = 0; j<b.size(); j++){
if(b[j] - a[i] <= r && b[j] - a[i] >= 0){
p = make_pair(a[i], b[j]);
result.push_back(p);
flag = true;
// cout << p.first << " aa\t" << p.second << endl;
}
}
if(flag == false){
for(int j = 0; j<b.size(); j++){
if(b[j] - a[i] >= 0){
p = make_pair(a[i], b[j]);
result.push_back(p);
// cout << p.first << " bb\t" << p.second << endl;
break;
}
}
}
}
for(int i = 0; i<result.size(); i++){
cout << result[i].first << ",\t" << result[i].second << endl;
}
}
int main(int argc, char **argv){
// pair<int, string> s;
// s = make_pair(3, "sd");
// cout << s.first << endl << s.second << endl;
func("A={1,3,5},B={2,4,6},R=1");
return 0;
}