long long int through scanf()?

how to get long long int input through scanf().
i tried using "%lld" and "%lli" placeholder ,but program always crashes.

the program should execute within an time constraint, i have been using std::cin which always causes a time limit exceeded.

is there a workaround in scanf() or any other input method faster than std::cin?

IDE - CodeBlocks 13.12
Compiler - gcc-4.7.1
Last edited on
Are you sure that C++11 is turned on? %lld is correnct fomat specifier to use in this case. Are you sure that you pass arguments correctly? Remember, scanf() expects pointers to values.

I have been using std::cin which always causes a time limit exceeded.Turn off c-streams synchronisation: std::cin.sync_with_stdio(false);
Place this at the beginning of main();
Comparison of different input methods: http://puu.sh/eUY2H/511ac8f0d4.png
Last edited on
yes - "have g++ follow the c++11 iso c++ language standard" is checked "on" in my compiler settings and,

could you please explain what std::cin.sync_with_stdio(false); does to cin and how it reduces my input time?
Last edited on
C and C++ standard streams are different. Each has own buffer and ways to access it.

To avoid situaltion when input already read from cin pops up in stdin, or when scanf discards chunks of input lying in cin buffer, those streams are synchronised. That means that every operation on cin includes synchronising own buffer with stdin, performing operation and synchronising stdin buffer with cin buffer. This incurs heavy cost on cin operations. Call to std::cin.sync_with_stdio(false); turns off that synchronisations. It is usually significantly speeds up cin operations (at least for libstdc++). After that you cannot mix C and C++ standard streams. You should stick with one.
Last edited on
you didn't answer the first response.

You need show the compile flags.
Topic archived. No new replies allowed.