ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1787. Turn for MEGA

WA #1 C++
Posted by Mary 27 Jul 2012 04:30
Hi guys I can't recognize what I've done wrong:

#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
    int b,c,d,k,n,a[99],TrafficJam=0;
    string line1, line2, line1p, line2p, sk, sn, sa[99];
    size_t pos,pos1[99];
    do
    {
           cout<<"Give first line"<<endl;
           getline (cin,line1);
           pos=line1.find(" ");
           sk=line1.substr(0,pos);
           line1p=line1.substr(pos+1);
           pos=line1p.find(" ");
           sn=line1p.substr(0,pos);
           if ( !(istringstream(sk) >> k) ) k=0;
           if ( !(istringstream(sn) >> n) ) n=0;
    }
    while ( ( sk.size() + sn.size() + 1 ) != line1.size() || k < 1 || k > 100 || n < 1 || n > 100);
    do
    {
          b=0;
          d=-1;
          cout<<"Give second line"<<endl;
          getline (cin, line2);
          line2p=line2;
          for (int i=0;i<n;i++)
          {
              pos1[i]=line2.find(" ");
              sa[i]=line2.substr(0,pos1[i]);
              line2=line2.substr(pos1[i]+1);
              istringstream(sa[i]) >> a[i];
              d+=sa[i].size()+1;
              if (a[i]<0 || a[i] > 100) b++;
          }
    }
    while (b!=0 || d!=line2p.size() );
    for (int i=0;i<n;i++)
    {
        TrafficJam=TrafficJam+a[i]-k;
        if(TrafficJam<0)
        TrafficJam=0;
    }
    cout<<TrafficJam<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Everything works, but still wrong answer test #1. Can you help? I've tried to find sth for many times, without success.
Re: WA #1 C++
Posted by Hyppocat (Adyghe SU) 27 Jul 2012 04:52
remove this - cout<<"Give second line"<<endl;
and this -  cout<<"Give first line"<<endl;


Edited by author 27.07.2012 05:01
Re: WA #1 C++
Posted by Mary 27 Jul 2012 14:52
ok thanks it works :D.
Why should I did that? Can't I add anything what only helps?
Re: WA #1 C++
Posted by Noob 27 Jul 2012 19:01
Testing system doesn't think that answer

Give first line
Give second line
0

is right.

It thinks that answer

0

is right.
Re: WA #1 C++
Posted by Mary 27 Jul 2012 20:42
Ok, thanks