#include<iostream>
#include<vector>
using namespace std;
int main(){
int a, b, tmp[4];
cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3];
int n;
cin >> n;
while(n--){
a = 0;
b = 0;
vector<int> cor(4);
vector<int> ps(4);
for(int i = 0; i < 4; i++){
cin >> ps[i];
cor[i] = tmp[i];
}
for(int i = 0; i < cor.size(); i++){
if(cor[i] == ps[i]){
a++;
cor.erase(cor.begin() + i);
ps.erase(ps.begin() + i);
i--;
}
}
for(int i = 0; i < cor.size(); i++){
for(int j = 0; j < ps.size(); j++){
if (cor[i] == ps[j]){
b++;
cor.erase(cor.begin() + i);
ps.erase(ps.begin() + j);
i--;
break;
}
}
}
cout << a << "A" << b << "B" << endl;
}
return 0;
}
其實不太懂程式怎麼結束的,求大神指點
多筆測資
所以要用while(cin >> ps[0] >> ps[1]......囉
多筆測資
所以要用while(cin >> ps[0] >> ps[1]......囉
對
多筆測資
所以要用while(cin >> ps[0] >> ps[1]......囉
對
#include<iostream>
#include<vector>
using namespace std;
int main(){
int a, b, tmp[4], n;
while(cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3]){
cin >> n;
while(n--){
a = 0;
b = 0;
vector<int> cor(4);
vector<int> ps(4);
for(int i = 0; i < 4; i++){
cin >> ps[i];
cor[i] = tmp[i];
}
for(int i = 0; i < cor.size(); i++){
if(cor[i] == ps[i]){
a++;
cor.erase(cor.begin() + i);
ps.erase(ps.begin() + i);
i--;
}
}
for(int i = 0; i < cor.size(); i++){
for(int j = 0; j < ps.size(); j++){
if (cor[i] == ps[j]){
b++;
cor.erase(cor.begin() + i);
ps.erase(ps.begin() + j);
i--;
break;
}
}
}
cout << a << "A" << b << "B" << endl;
}
}
return 0;
}
很好現在TLE了,結構上有沒有可能在優化呢