Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

The lead game (TLG) solution error

$
0
0

I am just teaching myself C++ programming and I was wondering if someone could critique this solution and tell me why it gives a wrong answer. For small solutions it gives the correct answers in my tests, but it gives a wrong answer when submitted. Any suggestions?

#include <iostream> using namespace std; int main () { int N=0; cin >> N; int i=0, winner=0, lead=0, P1s=0, P2s=0; while (i < N) { cin >> P1s >> P2s; if (lead < (P1s-P2s)) { winner = 1; lead = (P1s-P2s); } else if (lead < (P2s-P1s)) { winner = 2; lead = (P2s-P1s); } i++; } cout << winner << " " << lead << endl; return 0; }


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>