24h購物| | PChome| 登入
2013-08-23 17:01:53| 人氣3,361| 回應0 | 上一篇 | 下一篇

[UVA] 886 - Named Extension Dialing

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


 Named Extension Dialing 

The marketing research group of the S&TC (String & TinCan) telephone company recently concluded its analysis ofleading-edge services that could be developed for its CENTREX(business user) customers. The analysis showed that ``NamedExtension Dialing'' (NED) has the highest profit potential. Tomaximize profit by minimizing non-recurring expenses, S&TChas contracted your team to develop a module for the automatedattendant system that implements NED.


Currently when a call is placed to a business' primary number,the caller is greeted with the pleasant, and almost human,message ``You have reached XYZ Corporation. If you know yourparty's extension, please dial it now, or stay on the line for anoperator.'' NED will allow the sentence, ``If you know yourparty's name, dial the first letter of the first name followed bythe first letters of the last name of your party now,'' to beadded to the message.

Input 

Input to your software module will be a directory of names andextensions, one per line, followed by lines containing arbitrarynumeric strings dialed by people calling XYZ Corporation. These stringswill have more than 1 digit. Eachdirectory entry consists of a first name, one space, a last name,one space, and a 4-digit phone extension. Names can contain anycombination of up to twenty lower and upper case letters. Noinput line will exceed 80 characters.

Output 

For each dialed number, the program is to output, on one linestarting in the first column, the list of extensions to which thenumber could be referring. If the dialed number exactly matchesan extension, output the extension; otherwise, output the list of extensions that correspond with names that match thedialed number, the numbers should be output in the same order as theyappeared in the input.Multiple extensions that match a dialed number are to beseparated from each other by single spaces. The dialed numbermust match the characters in the name exactly. (Homophonicmatching of names was already completed in an earlier contest.)If the input fails to match any names or extensions, output `0'.

epsfbox{p886.eps}

Sample Input 

Barry Charles 4384
John Smith 2315
Susan Small 5764
Alexis Baxter 4652
Kim Rohde 6678
22
5764
2345
22298

Sample Output 

4384 4652
5764
0
4652



Miguel Revilla2004-09-16

題目描述:


看了很久才懂得題目。

輸入分別是姓和名、以及一個電話號碼,詢問則是一串數字,這個數字的第一個當作是這個人的姓,

接下來的數字都是這個人的名字(有可能打到一半),而假如這個數字剛好是某人的電話號碼則直接輸出。

當初以為如果要給 B 則要按 2 次 '2',事實上不用理會,按一次就可以了。

也就是 1 個數字對應多個可能英文字母。

然後找可能的匹配人名,依序輸入順序輸出電話號碼。





#include <stdio.h>
#include <string.h>
char firstName[1024][100], lastName[1024][100];
char dialing[1024][100];
char trans[1024][200];
char phone[] = "22233344455566677778889999";
char tolower(char c) {
    if(c >= 'A' && c <= 'Z')
        c += 32;
    return c;
}
int main() {
    char s[1024];
    int n = 0;
    int i, j, k;
    while(gets(s)) {
        if(s[0] >= '0' && s[0] <= '9')
            break;
        sscanf(s, "%s %s %s", firstName[n], lastName[n], dialing[n]);
        for(i = 0; firstName[n][i]; i++)
            firstName[n][i] = tolower(firstName[n][i]);
        for(i = 0; lastName[n][i]; i++)
            lastName[n][i] = tolower(lastName[n][i]);
        trans[n][0] = phone[firstName[n][0]-'a'];
        for(i = 0; lastName[n][i]; i++)
            trans[n][i+1] = phone[lastName[n][i]-'a'];
        n++;
    }
    do {
        int flag = 0;
        for(i = 0; i < n; i++) {
            if(!strcmp(s, dialing[i])) {
                flag = 1;
                puts(s);
                break;
            }
        }
        if(flag)    continue;
        for(i = 0; i < n; i++) {
            int ok = 1;
            for(j = 0; s[j] && ok; j++) {
                if(trans[i][j] != s[j])
                    ok = 0;
            }
            if(ok == 1) {
                if(flag)    putchar(' ');
                printf("%s", dialing[i]);
                flag++;
            }
        }
        if(flag == 0)
            puts("0");
        else
            puts("");
    } while(gets(s));
    return 0;
}

台長: Morris
人氣(3,361) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][向量] 10250 - The Other Two Trees
此分類上一篇:[UVA] 912 - Live From Mars

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