题目大意:不断地消除空格,使左右两边接触,求最后剩下多少个空格。 #include <iostream> using namespace std; int main() { int n; int a[15]; char c; while(scanf("%d", &n) != EOF && n) { for(int i = 1; i <= n; i++) a[i] = 0; for(int i = 1; i <= n; i++) { getchar(); for(int j = 1; j <= 25; j++) { c = getchar(); if(c == ' ') a[i]++; } } int minx = 30; for(int i = 1; i <= n; i++) { if(minx > a[i]) minx = a[i]; } int tot = 0; for(int i = 1; i <= n; i++) { tot += a[i] - minx; } cout << tot << endl; } return 0; }