第五题这样做不知道是不是很笨😣 #include<iostream> #include<string> #include<ctime> #include<vector> using namespace std; int main() { int l; cin >> l; srand(time(NULL)); int ba = (rand() % (10000 - 1000) + 1000); string b=to_string(ba); string c; for (int m = 0; m < l; m++) { cin >> c; int bb = 0; int dd = 0; vector<int> v; for (int a = 0; a < b.length(); a++) { if (b[a] == c[a]) { bb = bb + 1; } else if (b[a] != c[a]) { v.push_back(a); } } for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { for (vector<int>::iterator its = v.begin(); its != v.end(); its++) { if (b[*it] == c[*(its)] && it != its) { dd = dd + 1; } } } cout << "你对了" << bb << "个数字" << endl; cout << "其中你有" << dd << "在里面但是位置不对" << endl; } cout << "最终数字为" << b << endl; }