Translate

Views

Thursday, July 25, 2019

Solution Kattis: Stand on Zanzibar

https://open.kattis.com/problems/zanzibar
#include<bits/stdc++.h>
using namespace std;

int T, n, ans;
vector<int> v;

int main(){ 
 cin >> T;
 while(T--){ ans=0; v.clear();
 
  while(cin>>n){
   if (n==0) break;
   v.push_back(n);
  }
  
  for(int i=1; i<v.size(); i++){
   if (v[i]/v[i-1]<2) continue;
   ans+=v[i]-v[i-1]*2;
  }
  
  cout<<ans<<"\n";
 }
}
Good luck! If you need help please leave a comment :) 

No comments: