int c;while((c = getchar()) != '\n' && c != EOF);在 while(scanf("%d",&n)!=EOF)的大括号{}里面加入while((c = getchar()) != '\n' && c != EOF);