+ 1
Can anyone covert this Python code in C++ ?
i don't understand the second for loop how should i convert that!! N=10 Team_G = [9,7,6,6,5,5,3,3,2,1] Team_O = [9,7,6,6,6,3,2,2,0,0] sol=0 for i in range(N): for k in range(len(Team_O)): if Team_G[i] > Team_O[k]: sol += 1 Team_O.pop(k) break print(sol) https://code.sololearn.com/cqGNMF93Rn35/?ref=app
2 Antworten
+ 1
Ahnaf well i have asked specifically about 2nd for loop but i have converted it already.
if anyone is interested in answer here it is:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 10;
vector<int> Team_G = {9,7,6,6,5,5,3,3,2,1};
vector<int> Team_O = {9,7,6,6,6,3,2,2,0,0};
int sol = 0;
for(int i = 0; i<10; i++){
for(int k = 0; k<Team_O.size(); k++){
if(Team_G[i]>Team_O[k]){
sol += 1;
Team_O.erase (Team_O.begin() + k);
break;
}
}
}
cout<<sol;
return 0;
}
0
Thank you for posting a question on the SL QnA forum. But unfortunately this is not a place for code translation. If you have any specific problem for transportation, you can post that here. I hope you understand what I mean 😄