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 1423. String Tale

Please help: reading lines in C++ (+)
Posted by Michael Rybak (accepted@ukr.net) 11 Feb 2006 18:49
What is the C++ *fast* analog for pascal's Readln?

I used any of 3 methods:

1.
     cin.getline(vs1, MAX_STR_L);
     cin.getline(vs2, MAX_STR_L);

2.
     getline(cin, s1);
     getline(cin, s2);

3.
     while(..) {..scanf("%c", &c)..}

Either of them is very slow (AC in 0.109), and running at my home PC shows  that algo works *way* faster than reading input itself. So, someone who got AC in 0.015 in C++, please help.

Edited by author 11.02.2006 18:50
Re: Please help: reading lines in C++ (+)
Posted by void off() 11 Feb 2006 19:04
Is scanf("%s",s1) also slow?
Try gets()
Posted by Vladimir Yakovlev (USU) 11 Feb 2006 19:14
AC in 0.031, thanks a lot! (-)
Posted by Michael Rybak (accepted@ukr.net) 11 Feb 2006 19:51
-

Edited by author 11.02.2006 19:51
Re: Please help: reading lines in C++ (+)
Posted by Slawomir Tadeja 15 Jun 2006 03:14
Try this:

#include <iostream>
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0); // <- this line
  // Now synchronize I/O is off.

With this line my programs works 0.001 (if algorithm is good enough ;-).