UVa414 - Machined Surfaces- 字符串-难度1
来源:互联网 发布:如何开淘宝店铺 编辑:程序博客网 时间:2024/05/21 14:53
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=355
Machined Surfaces
An imaging device furnishes digital images of two machined surfaces that eventually will be assembled in contact with each other. The roughness of this final contact is to be estimated.
A digital image is composed of the two characters, "X" and " " (space). There are always 25 columns to an image, but the number of rows, N, is variable. Column one (1) will always have an "X" in it and will be part of the left surface. The left surface can extend to the right from column one (1) as contiguous X's.
Similarly, column 25 will always have an "X" in it and will be part of the right surface. The right surface can extend to the left from column 25 as contiguous X's.
Digital-Image View of Surfaces
Left Right
XXXX XXXXX
XXX XXXXXXX
XXXXX XXXX
XX XXXXXX
. .
. .
. .
XXXX XXXX
XXX XXXXXX
1 25
In each row of the image, there can be zero or more space characters separating the left surface from the right surface. There will never be more than a single blank region in any row.
For each image given, you are to determine the total ``void" that will exist after the left surface has been brought into contact with the right surface. The ``void" is the total count of the spaces that remains between the left and right surfaces after theyhave been brought into contact.
The two surfaces are brought into contact by displacing them strictly horizontally towards each other until a rightmost "X" of the left surface of some row is immediately to the left of the leftmost "X" of the right surface of that row. There is no rotation or twisting of these two surfaces as they are brought into contact; they remain rigid, and only move horizontally.
Note: The original image may show the two surfaces already in contact, in which case no displacement enters into the contact roughness estimation.
Input
The input consists of a series of digital images. Each image data set has the following format:
- First line -
- A single unsigned integer, N, with value greater than zero (0) and less than 13. The first digit of Nwill be the first character on a line.
- Next N lines -
- Each line has exactly 25 characters; one or more X's, then zero or more spaces, then one or more X's.
The end of data is signaled by a null data set having a zero on the first line of an image data set and no further data.
Output
For each image you receive as a data set, you are to reply with the total void (count of spaces remaining after the surfaces are brought into contact). Use the default output for a single integer on a line.
Sample Input (character "B" for ease of reading. The actual input file will use the ASCII-space character, not "B").
4XXXXBBBBBBBBBBBBBBBBXXXXXXXXBBBBBBBBBBBBBBBXXXXXXXXXXXXBBBBBBBBBBBBBBBBXXXXXXBBBBBBBBBBBBBBBBBXXXXXX2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXBBBBBBBBBBBBBBXX0
Sample Output
400
代码加思路:
/* *1)主要是题意的理解: *意思是把左边X整体移过来使他和右边的X最少有一个接触, *问现在两边的X中间有多少个空格。 *2)题目给出的数据是'B'最后要改为' ' */#include <iostream>#include <cstdio>using namespace std;int main(){#ifdef LOCALfreopen("f:\\input.txt", "r", stdin);#endifint n;while(scanf("%d", &n)){if(n == 0) break;getchar();//消回车,使用"%c",获得字符,需要注意消回车'\n'char m;int a[14] = {0};int count = 0;int min = 25;//min保存最小的空格数for(int i = 1; i <= n ; ++i){while(1){scanf("%c", &m);if(m == '\n') break;if(m == ' ') count++;// 测试的是‘B’,需要改过来}if(count < min) min = count;a[i] = count;count = 0;}int sum = 0;for(int i = 1; i <= n ; ++i){sum += a[i] - min;}cout << sum << endl;}return 0;}
- UVa414 - Machined Surfaces- 字符串-难度1
- uva414 Machined Surfaces
- UVa414 Machined Surfaces
- UVa414 - Machined Surfaces
- UVA414 - Machined Surfaces
- UVA414—— Machined Surfaces
- UVALive5389 UVA414 POJ1493 ZOJ1339 Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- Machined Surfaces
- 414 - Machined Surfaces
- UVAOJ 414 - Machined Surfaces
- POJ 1493 Machined Surfaces
- UVa 414 - Machined Surfaces
- Oracle常用知识小结
- DSP/BIOS程序开发三:API简介
- XE3使用Spirit写解析器
- Insert Interval
- Java继承--问题
- UVa414 - Machined Surfaces- 字符串-难度1
- OpenCV笔记:图像边缘检测Sobel,Laplace,Canny
- ##、“...”、_ _VA_ARGS_ _
- protobuf c++ API
- Linux--DNS服务器
- 基于visual Studio2013解决面试题之1306奇偶位数交换
- 数据分析之数据采集
- 老妖怪个人建议环境保护低碳生活22条
- JAVA --set list map