c++ - getchar_unlocked() slowing down execution time -


i attempting problem on codechef input array of size n, , have output number repeats in array along count.

problem link :: http://www.codechef.com/problems/maxcount/

i first wrote code using scanf input, , got ac execution time(0.94s) pretty near allowed time(1s). had read getchar_unlocked() decreases input time, , hence tried implement using getchar_unlocked. instead got me time limit exceeded error.

the code using getchar_unlocked ::

#include <iostream> #include <cstdio>  using namespace std;  void fastread(int* a) {  char c=0;  while (c<33) c=getchar_unlocked();  *a=0;  while (c>33) {     *a=*a*10+c-'0';     c-getchar_unlocked(); } }  int main() { int cases; int size,in; fastread(&cases); while(cases--) {     int arr[100001]={0};     int max=0;     int index=0;     fastread(&size);     for(int i=0; i<size; i++)     {         fastread(&in);         arr[in]++;         if(arr[in]==max)         {             if(in<index)                 index=in;         }         if(arr[in]>max)         {             max=arr[in];             index=in;         }     }     printf("%d %d\n", index, max); } return 0; } 

was there wrong in way implemented code? thank you!

if that's actual code, then

c-getchar_unlocked(); 

will cause infinite loop since c never modified.

i suspect want

c = getchar_unlocked(); 

using space bar won't make code run slower , makes code more readable.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -