Recently I tried using getchar to take in char input (c++), the sample works fine on my compiler , but got idleness limit exceeded on judge, I tried the code in custom invocation, and it turns out getchar was reading random characters lol. My code is something like
for(int i=0;i<n;++i) for(int j=0;j<n;++j) while(grid[i][j]!='.'&&grid[i][j]!='#') grid[i][j]=getchar()
Does anyone know how to fix this problem? Thank you!! :)
Why not use
cin
orscanf
?But isn't this the same as the code I provided? Since the while grid[i][j] != expected input I will do another getchar? Thanks.