24h購物| | PChome| 登入
2013-05-09 08:59:37| 人氣666| 回應0 | 上一篇 | 下一篇

[UVA][字串處理] 10352 - Count the eWords

推薦 0 收藏 0 轉貼0 訂閱站台

Problem H

Count the eWords

Input: standard input

Output: standard output

Time Limit: 2 seconds

Memory Limit: 32 MB

 

The Malfunction Checkers Ltd (MCL) is famous for its extraordinary ability to find faults of a malfunctioning device. Many companies depend on it to find out faults of their newly developed products such as TV, VCR, Radio etc.

Few days ago, the administrator of MCL has come to know that someone has been trying hard to damage MCL's reputation by installing an email virus in the main server of MCL. To track this attempt, the administrator has planned to read all incoming emails. But the employees of MCL are very cautious about their privacy and are opposing the plan. As a result, administrator has to change his plan: instead of reading emails, he is planning write a program to count the words in each email and analyze the result.

What the administrator does not know is that the main server's C compiler is already infected. A virus has tactfully damaged some libraries of the compiler. As a result, the strcmp() function of the compiler works in an unexpected way. The problems are:

  • It ignores the letters in the 3rd position during comparison.
  • The function decides its return value considering only the starting 5 letters.

You are to find out the output of the program written by the administrator.

Input

Input contains sevaral emails, each ends with the word '#' which should not be counted. The input file is terminated by end of file (EOF).

Each email contains a numbers of lines of words. The words may contains any 'readable' character ( except '#' ) and have maximum length of 20. The number of distinct words is limited to 4100, but any word may appear more than once.

Output

Each email's output starts with "Set #n:" line, and ends with an empty line.

The output shows in each line a distinct word truncated after length 5, a space, and then the number of times it appears. The lines are ordered in ascending (ASCII) order of the words. The 'ignored' (i.e. the 3rd) letter in the word should show the last 'ignored' letter. However, the sorting should be according to the first 'ignored' letter. For Example if the email contains the line “tid tim tis” then you should consider the three words as one word and print them as “tis” (the last word in this group), but while producing the sorted output you should sort them considering them as “tid” (the first one in this group)

Sample Input

This is an longinput string
sort the this line if is has soft line break
#
this is a set of sit
#
timk tidk tisk tia tiy tiz
#

Sample Output

Set #1:

This 1

an 1

break 1

has 1

if 1

is 2

line 2

longi 1

soft 2

strin 1

the 1

this 1

 

Set #2:

a 1

is 1

of 1

set 1

sit 1

this 1

 

Set #3:

tiz 3

tisk 3


Mustaq Ahmed

題目描述有錯啊!!

題目描述有錯啊!!

輸出的時候,排序要按照忽略的映射字串進行排序,
而不是它題目所說的要去找第一個被忽略的字串去排序。


用了很多內建(汗

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <map>
using namespace std;
int main() {
    string s, o;
    int cases = 0;
    while(1) {
        map<string, pair<int, pair<string, string> > > R;
        map<string, pair<int, pair<string, string> > >::iterator it;
        // ignore, count, first, last
        while(1) {
            if(getline(cin, s)) {
                if(s == "#")    break;
                stringstream sin(s);
                while(sin >> s) {
                    if(s.length() >= 5)
                        s = s.substr(0, 5);
                    o = s;
                    if(s.length() >= 3)
                        o[2] = '$';
                    if(R.find(o) == R.end())
                        R[o] = make_pair(1, make_pair(s, ""));
                    else {
                        it = R.find(o);
                        R[o] = make_pair((it->second).first+1, make_pair((it->second).second.first, s));
                    }
                }
            }
            else    return 0;
        }
        map<string, pair<int, string> > Ans;
        map<string, pair<int, string> >::iterator jt;
        for(it = R.begin(); it != R.end(); it++) {
            if((it->second.second).second != "")
                Ans[it->first] = make_pair((it->second).first, (it->second).second.second);
            else
                Ans[it->first] = make_pair((it->second).first, (it->second).second.first);
            //cout << (it->second).second.first << " " << (it->second).second.second << endl;
        }
        printf("Set #%d:\n", ++cases);
        for(jt = Ans.begin(); jt != Ans.end(); jt++) {
            if((jt->second).second != "")
                cout << (jt->second).second;
            else
                cout << jt->first;
            cout << " " << (jt->second).first << endl;
        }
        puts("");
    }
    return 0;
}
/*
xxab xxbb xxba xxaa
#
cd cde
#

Output:
Set #1:
xxaa 2
xxbb 2

Set #2:
cd 1
cde 1
//Wrong the problem description
//we should sort by xx-b and xx-a,
//and output the last ignored word.
*/

台長: Morris
人氣(666) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][組合、排容] 12572 - RMQ Overkill
此分類上一篇:[UVA][線段交點、射線法] 10321 - Polygon Intersection

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文