首页 > 代码库 > 414 - Machined Surfaces

414 - Machined Surfaces

Sample Input (character "B" for ease of reading. The actual input file will use the ASCII-space character, not"B").

 

4XXXXBBBBBBBBBBBBBBBBXXXXXXXXBBBBBBBBBBBBBBBXXXXXXXXXXXXBBBBBBBBBBBBBBBBXXXXXXBBBBBBBBBBBBBBBBBXXXXXX2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXBBBBBBBBBBBBBBXX0

 

Sample Output

 

400

----------------------------------------
题目很难看懂,大意就是计算每次总得空格数,以及获得每行最小的空格数,输出sum - min*linNum。
AC代码:
注意第11行getchar()。后面scanf("%c”,&ch)的话会先获得换行符。
 1 #include<stdio.h> 2 int main(){ 3     int n; 4     int i; 5     int min = 1000, sum,tmp; 6     char ch; 7  8     while(scanf("%d",&n) != EOF){ 9         printf("n:%d\n",n);10         if(n == 0) break;11         getchar();12         sum = 0; min = 1000;  13         for(i = 0; i < n;i++){14             tmp = 0;15             while(1){16                 scanf("%c",&ch);
17
18 if(ch == ){19 tmp++;20 sum++;21 }22 else if(ch == \n)23 break;24 }25 min = min > tmp ? tmp:min;26 }27 printf("%d\n",(sum - min*n));28 29 }30 return 0;31 }

414 - Machined Surfaces