#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <stack> #include <queue> #include <algorithm> #include <string> const int inf = (1<<31)-1; const int MAXN = 1e3+10; using namespace std; char ts[MAXN]; int main() { int t,len; int a,b; scanf("%d",&t); while(t--){ a = b = 0; while(gets(ts)!=NULL&&strcmp(ts,"##")!=0){ len = strlen(ts); int k=0; //记录空格 for(int i=0;i<len;i++){ if(ts[i]==' '){ k++; continue; } if(ts[i]=='\t'){ k+=4; a++; continue; } k = 0;//如果是其他字符,k清零 } //字符创最后一个字符为'\0',也就是换行了,所以直接相加就可以了 b += k; } printf("%d tab(s) replaced\n",a); printf("%d trailing space(s) removed\n",b); } //cout << "Hello world!" << endl; return 0; } |
Double click to view unformatted code.