UVALive5389 UVA414 POJ1493 ZOJ1339 Machined Surfaces

Regionals 1995 >> North America - East Central NA

问题链接UVALive5389 UVA414 POJ1493 ZOJ1339 Machined Surfaces

题意简述:输入若干测试实例,每个实例首先输入n,之后输入n行字符串,若n=0则程序结束。每行的字符串包含字符"X"和空格,"X"在两边,空格在中间。可以用左边或右边的X去填充中间的空格,每行填充的"X"都一样多,问某行空格被填充完时,总共还剩下多少空格。

问题分析:这个问题实际上就是统计空格数和找空格最少行有多少空格问题。剩余空格数=总空格数-空格最少行的空格数×n。

程序说明:直接按字符读入处理,没有使用输入缓冲区。

AC的C语言程序如下:

/* UVALive5389 UVA414 POJ1493 ZOJ1339 Machined Surfaces */

#include <stdio.h>

#define MAX 100000

int main(void)
{
    int n, sum, min, count, i;
    char c;

    while(scanf("%d\n", &n) != EOF && n != 0) {
        sum = 0;
        min = MAX;
        for(i=1; i<=n; i++) {
            count = 0;

            c = getchar();
            while(c != '\n') {
                if(c == ' ') {
                    sum++;
                    count++;
                }
                c = getchar();
            }

            if(count < min)
                min = count;
        }

        printf("%d\n", sum - min * n);
    }

    return 0;
}

时间: 2024-08-29 18:47:58

UVALive5389 UVA414 POJ1493 ZOJ1339 Machined Surfaces的相关文章

UVa 414 - Machined Surfaces

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=355 题目:每行25个字符,左开始为X,右边也是X,中间为空格B:当所有行的左右X相互向内移动,直到有一行左右X相遇:这时所有行中间一共还有多少空格B. 思路:中间空格最少的行一定最先相遇,即X最多的行最先相遇:当X最多行相遇时,每行减少的空格数相同,则用X最

UVA - 414 Machined Surfaces(题意不好懂)

懂了题意就是水题. 给你n行数每行都有25个字符,第一个和最后一个都是'X',中间可能包含空格,问每次与左边(或者右边)移动,直到中间没有空格为止,问此时还有多少空格. 我们直接考虑移动完之后的状态,肯定是空格少的那一行最先移动完,那么只要统计出原先总的空格数减去空格最少的那一行乘×n就是目前剩下的字符了. #include<cstdio> #include<cstring> int main() { int n,i,j,m,sum,maxn; char s[30]; while(

UVA_414:Machined Surfaces

Language : C++ 4.8.2 #include<stdio.h> #include<string.h> int main(void) { int n; int sum; // 记录每一组数据里面所有空格的个数 int count; // 记录单行的个数 int length; int min_space; char str[30]; while(1) { min_space = 25; sum = 0; scanf("%d\n", &n);

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 XXXXXXXXXXX

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

Rendering Transparent 3D Surfaces in WPF with C#(转载)

Rendering Transparent 3D Surfaces in WPF with C# The primary problems that arise when rendering semi-transparent 3d objects in Windows Presentation Foundation have to do with false z-buffer occlusions. Specifically, when a transparent surface or poly