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 1612. Tram Forum

WA #2 - C++
Posted by really 8 Jan 2009 17:16
#include <string>
#include <algorithm>
#include <iostream>
//#include <conio.h>

using namespace std;
string tekst;
int tram = 0;
int trolleybus = 0;
size_t c; //zmienna pomocniczna

int main()
{

getline(cin, tekst);

//zliczamy wystapienia "tram" i "trolleybus"
for (int i = tekst.find("tram", 0); i!=string::npos;i = tekst.find("tram",i))
{
   if ((tekst.length() - i == 4 && (tekst[i-1]<97 || tekst[i-1]>122)) || (tekst[i-2]=='\\' && tekst[i-1]=='n'))
 {
 tram++;

}

  if(tekst.length() - i > 4)
 {

  if ((tekst[i-1]<97 || tekst[i-1]>122) && (tekst[i+4]<97 || tekst[i+4]>122))
  tram++;

  }
 i++;
}

for (int j = tekst.find("trolleybus", 0); j!=string::npos;j = tekst.find("trolleybus",j))
{
   if ((tekst.length() - j == 10 && (tekst[j-1]<97 || tekst[j-1]>122)) || (tekst[j-2]=='\\' && tekst[j-1]=='n') )
 {
 trolleybus++;

}

  if(tekst.length() - j > 10)
 {

  if ((tekst[j-1]<97 || tekst[j-1]>122) && (tekst[j+10]<97 || tekst[j+10]>122))
  trolleybus++;

  }
 j++;
}
 if (tram > trolleybus) cout << "Tram driver";
 if (trolleybus > tram) cout << "Trolleybus driver";
 if (trolleybus == tram) cout << "Bus driver";


//system("PAUSE");
return 0;
}

I don't have any idea what is wrong in this code.
97-122 are the numbers of lowercase letters in ASCII

Edited by author 08.01.2009 17:17

Edited by author 08.01.2009 17:39
Re: WA #2 - C++
Posted by d340934 8 Jan 2009 18:13
You are reading only first line from input :) instead waiting on EOF
Re: WA #2 - C++
Posted by really 8 Jan 2009 18:22
Oh god, big thanks. Epic fail;)
Re: WA #2 - C++
Posted by Mihail Nikalyukin(It-Team) 22 Feb 2010 12:01
can u give me advice
how i must read all lines in c#?