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 1003. Parity

Reading strings on C++
Posted by Igor E. Tuphanov 6 Jan 2006 09:54
Strange. It's already second prob., wich got WA #1, where I've got to read strings from input.
FE, in this prob., I used two methods reading word in the end of line (all tests, I tested my solution were correct):

      cin.getline(ss,sizeof(ss)); s.assign(ss);
      while (s[0] == ' ') s.erase(s.begin());
      while (s[s.length()-1] == ' ') s.erase(s.begin() + s.length() - 1);
      if (s == "odd") p[i] = 1; else p[i] = 0;

And the second one:

      scanf("%s",ss);
      if (ss[0] == 'o') p[i] = 1; else p[i] = 0;

Both got WA #1. Am I wrong?

Edited by author 06.01.2006 09:56
Re: Reading strings on C++
Posted by Igor E. Tuphanov 7 Jan 2006 08:06
As I can see now, this prob. is kind of stupid. Everyone got WA #1. Or bug was fixed?
Re: Reading strings on C++
Posted by wsogenius 16 Nov 2007 15:06
hi guy this program may help you:)

#include <iostream>
#include <iomanip>
#inlcude <string>

using namespace std;

int main()
{
   string aStr;
   getline(cin,aStr);
   cout<<aStr<<endl;
   getline(cin,aStr,"\n");
   cout<<aStr<<endl;
}