[ACM] 常用程式片段
Debug用
進階版getch(), ungetch() (from K&R)
#ifndef ONLINE_JUDGE
freopen("848_input.txt", "r",stdin);
freopen("848_output.txt","w",stdout);
#endif
進階版getch(), ungetch() (from K&R)
// ungetch(): push a char to stack
// getch(): if stack is not empty, pop a char
// or get a char from stdin.
int buffer[1024];
int top = -1; //stack pointer
void ungetch(int c){
buffer[++top] = c;
}
int getch(){
if(top > -1)
return buffer[top--];
else
return getchar();
}
留言
張貼留言