固定左右兩邊形狀,合併後會有多少個空格
想法:
計算每一列有多少個X,並找出哪一列有最多個X,值為Max,則該列空格就是(Max-該列有幾個X)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
int main() | |
{ | |
// freopen ("input.txt","rt",stdin); | |
int N; | |
while (scanf("%d",&N)){ | |
if (!N) break; | |
int nOfX[20]={0},Max = 0; | |
char line[30]; | |
gets(line); | |
for (int i=0; i<N; i++){ | |
gets(line); | |
for (int j=0; line[j]; j++) | |
if (line[j]=='X') nOfX[i]++; | |
if (nOfX[i]>Max) | |
Max = nOfX[i]; | |
} | |
int ans = 0; | |
for (int i=0; i<N; i++) | |
ans += (Max-nOfX[i]); | |
printf("%d\n",ans); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言