414 - Machined Surfaces

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

4
XXXXBBBBBBBBBBBBBBBBXXXXX
XXXBBBBBBBBBBBBBBBXXXXXXX
XXXXXBBBBBBBBBBBBBBBBXXXX
XXBBBBBBBBBBBBBBBBBXXXXXX
2
XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXBBBBBBBBBBBBBBXX
0

Sample Output

4
0
0 ----------------------------------------
题目很难看懂,大意就是计算每次总得空格数,以及获得每行最小的空格数,输出sum - min*linNum。
AC代码:
注意第11行getchar()。后面scanf("%c”,&ch)的话会先获得换行符。
 #include<stdio.h>
int main(){
int n;
int i;
int min = , sum,tmp;
char ch; while(scanf("%d",&n) != EOF){
printf("n:%d\n",n);
if(n == ) break;
getchar();
sum = ; min = ;
for(i = ; i < n;i++){
tmp = ;
while(){
scanf("%c",&ch);
17
if(ch == ' '){
tmp++;
sum++;
}
else if(ch == '\n')
break;
}
min = min > tmp ? tmp:min;
}
printf("%d\n",(sum - min*n)); }
return ;
}
上一篇:百度地图代码API


下一篇:M公司面试