我是c ++的新手,我希望你们能帮助我,我是一个初学者
int main(){
int n,g;
while(cin>>n>>g){
int win=0;
vector<int>v;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
if(a>b)
win+=3;// win+=3 is outside the "if part" , it's the first time I see something like this ,what does it do? Doesn't the if part need the {} too?
else{
if(a==b)
win++;
v.push_back(b-a); //what does this line do?
答案 0 :(得分:1)
这只是一个浓缩的单行if语句。
if(a>b)win+=3;
这可以改写为
if (a>b)
{
win = win + 3;
}
以下一行
v.push_back(b-a)
计算b - a
的差异,然后使用push_back
将其添加到vector
v
的末尾。