首页 > 代码库 > CSUOJ 1854 Refrigerator Magnets

CSUOJ 1854 Refrigerator Magnets

1854: Refrigerator Magnets

        Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted: 96     Solved: 23    


Description

Like many families with small children, my family’s refrigerator is adorned with a set of alphabet magnets: 26 separate magnets, each containing one letter of the alphabet. These magnets can be rearranged to create words and phrases. I feel it is my parental duty to use these magnets to create messages that are witty and insightful, yet at the same time caring and supportive. Unfortunately, I am somewhat hindered in this task by the fact that I can only make phrases that use each letter once.

For example, a nice inspiring message to leave for the children might be, “I LOVE YOU.” Unfortunately, I cannot make this message using my magnets because it requires two letter "O"s. I can, however, make the message, “I LOVE MUSTARD.” Admittedly this message isn‘t as meaningful, but it does manage to not use any letters more than once.

You are to write a program that will look at a list of possible phrases and report which phrases can be written using refrigerator magnets.

Input

The input will consist of one or more lines, ending with a line that contains only the word “END”. Each line will be 60 characters or less, and will consist of one or more words separated by a single space each, with words using only uppercase letters (A–Z). There will not be any leading or trailing whitespace, and there will not be any blank lines.

Output

Output only the lines which can be written in refrigerator magnets—that is, the lines which have no duplicate letters. Output them exactly the same as they were in the input—white spaces and all. Do not output the final “END” string.

Sample Input

I LOVE YOU
I LOVE MUSTARD
HAPPY BIRTHDAY
GLAD U BORN
SMILE
IMAGINE
WHATS UP DOC
HAVE A NICE DAY
END

Sample Output

I LOVE MUSTARD
GLAD U BORN
SMILE
WHATS UP DOC

Hint

Source

2011 Mid-Central USA Regional Contest

 

http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1854

 

这题结尾判断应为前三个字符END,而非整个字符串为END,有多余输出

然后坑死了一大堆人....

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;

int main()
{
    char s[105];
    int num[105];

    while(1) {
        gets(s);
        if(s[0] == ‘E‘ && s[1] == ‘N‘ && s[2] == ‘D‘) break;
        int flag = 0;
        memset(num, 0, sizeof(num));
        int len = strlen(s);
        for(int i = 0; i < len; i++) {
            if(s[i] == ‘ ‘) continue;
            num[s[i] - ‘A‘]++;
        }
        for(int i = 0; i < 27; i++) {
            if(num[i] >= 2) flag = 1;
        }
        if(flag) continue;
        else puts(s);
    }


    return 0;
}

  

 

CSUOJ 1854 Refrigerator Magnets