这是水题,注意的是空格只有最后才算的,中间出现的空格都不算
#include
#include
#include
#include
#include
#pragma warning(disable:4996) using namespace std; char s[1010]; int main() { int t; scanf("%d", &t); getchar(); while (t--) { int tab=0,sp=0,i,num=0; while (gets(s)) { sp = 0; if (strcmp(s, "##") == 0) break; for (i = 0; i < strlen(s); i++) { if (s[i] == '\t') { tab++; sp += 4; continue; } else if (s[i] == ' ') { sp++; continue; } sp = 0; } num += sp; } printf("%d tab(s) replaced\n",tab); printf("%d trailing space(s) removed\n", num); } return 0; }