poj 1493 Machined Surfaces

简介:

这道题的难点在于读题,题读懂了,基本就是很水很水的题目。。。

题意:每张照片由n行串组成,每行串长度为25,都由X开头,空格中间(也可没有),X结尾。所有串的左边X部分同时右移,直到有一个串没有空格。问这时所有串合起来总共有几个空格。 

思路:求最短的空格数min,每一行的空格数减去min之和就是结果了。


AC的代码:

#include <iostream>

int blankNum[15];
char img[30];

int main()
{
	int n;
	while(scanf("%d",&n))
	{
		if(n==0)
			return 0;

		getchar();

		int i,j;
		int min=999;
		int tmp;
		for(i=1;i<=n;i++)
		{
			tmp=0;
			gets(img);
			for(j=0;j<25;j++)
				if(img[j]==' ')
					tmp++;

			blankNum[i]=tmp;

			if(tmp<min)
				min=tmp;
		}

		for(i=1,tmp=0;i<=n;i++)
			tmp+=blankNum[i]-min;

		printf("%d\n",tmp);
	}
	
	return 0;
}


相关文章
POJ 2027 No Brainer
POJ 2027 No Brainer
82 0
|
人工智能 机器学习/深度学习
poj 3664
http://poj.org/problem?id=3664 进行两轮选举,第一轮选前n进入第二轮,第二轮选最高   #include #include using namespace std; struct vote { int a,b; int c; ...
706 0
POJ-1003-hangover
Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length.
737 0
poj题目分类
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html
759 0