POJ3916 UVALive4574 Duplicate Removal【水题】

Duplicate Removal
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2016 Accepted: 1396

Description

The company Al's Chocolate Mangos has a web site where visitors can guess how many chocolate covered mangos are in a virtual jar. Visitors type in a guess between 1 and 99 and then click on a "Submit" button. Unfortunately, the response time from the server is often long, and visitors get impatient and click "Submit" several times in a row. This generates many duplicate requests.
Your task is to write a program to assist the staff at ACM in filtering out these duplicate requests.

Input

The input consists of a series of lines, one for each web session. The first integer on a line is N, 0 < N ≤ 25, which is the number of guesses on this line. These guesses are all between 1 and 99, inclusive. The value N = 0 indicates the end of all the input.

Output

For each input data set, output a single line with the guesses in the original order, but with consecutive duplicates removed. Conclude each output line with the dollar sign character '$'. Note that there is a single space between the last integer and the dollar sign.

Sample Input

5 1 22 22 22 3
4 98 76 20 76
6 19 19 35 86 86 86
1 7
0

Sample Output

1 22 3 $
98 76 20 76 $
19 35 86 $
7 $

Source

Mid-Central USA 2009

问题链接POJ3916 UVALive4574 Duplicate Removal
问题简述:(略)
问题分析
    这个题是去除重复,把相邻重复的数去掉。关键是没有必要用数组存储数据,按序列处理即可。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* POJ3916 UVALive4574 Duplicate Removal */

#include <stdio.h>

int main(void)
{
    int n, a, last;
    while(scanf("%d", &n) != EOF && n) {
        last = -1;
        while(n--) {
            scanf("%d", &a);
            if(a != last)
                printf("%d ", a);
            last = a;
        }
        printf("$\n");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10237001.html