24h購物| | PChome| 登入
2013-08-23 11:45:33| 人氣1,811| 回應0 | 上一篇 | 下一篇

[UVA] 10761 - Broken Keyboard

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

Problem C
Broken Keyboard
Input: standard input
Output: standard output
Time Limit: 1 second




Certain letter keys on a keyboard are broken but all non-letter keys are fully functional. Yet we have to type a text and we would like to know how many complete lines of the text we can type. Additionally, we would like to know which other letter keys can be broken such that we still can type the same lines from the text.

Input

Your program should read input from standard input. The input includes a number of cases. The first line of each case lists a sequence of letters whose keys are broken. The following lines contain the text that we would like to type. This text ends with the following line

END

 

which should be also processed. No line of input is longer than 80 characters. The input is terminated by a case whose first line is

 
finish 

and this case is not to be processed.

Output

The output should be formatted as a table, see the sample output. The header of the table occupies 4 lines and is shown below following an additional line numbering character positions; this line is not a part of the header.

12345678901234567890123456789012345678901234567890123456789
+----------+----------------+-----------------------------+
| Keyboard | # of printable | Additionally, the following |
|          |      lines     |  letter keys can be broken  |
+----------+----------------+-----------------------------+

In the remaining rows of the table, you should output two lines for each case of input in the following format, see also the sample output.

  • The first column of the table reports the number of the keyboard. Keyboards are numbered sequentially, starting with 1. This number should be printed right adjusted at characters 5-7 of the line. There will be no more that 999 keyboards in the input file.
  • The second column of the table reports how many lines of the text of this case can be typed with our broken keyboard. This number should be printed right adjusted at characters 19-21 of the line. There will be no more that 999 lines of text in each case.
  • The third column of the table reports which additional letter keys can be broken such that we still can type the lines reported in column two. The additional letter keys should be listed as a sequence of small letters in alphabetic order starting at the 31st character of the line.
  • The second line of output for each case is a horizontal line as shown in the sample output.

The only white-space characters used in the table are space and new-line.

Sample Input

Xyz
We will work with a basic time unit of an eighth-note. At any
given time, your left foot and right foot will each be on distinct
arrows. Only one foot may perform an action (changing arrows and/or
tapping) during any time unit; jumping is not allowed. Also, you must
remain facing forward in order to see the screen. This puts
limitations on which feet you can use to hit which arrows. Finally,
hitting two arrows in a row with the same foot ("double-tapping") is
exhausting, because you can't shift your weight onto that
foot. Ideally, you want to alternate feet all the way through a string
of consecutive arrows.
END
life
is 
sometimes
tough
END
but
one 
must 
not 
give 
up
END
finish

 

 

Output for Sample Input

+----------+----------------+-----------------------------+
| Keyboard | # of printable | Additionally, the following |
|          |      lines     |  letter keys can be broken  |
+----------+----------------+-----------------------------+
|     1    |        4       | jkq                         |
+----------+----------------+-----------------------------+
|     2    |        1       | abcdjkmnpqrsvwxyz           |
+----------+----------------+-----------------------------+
|     3    |        3       | acfhjklmpqrswxyz            |
+----------+----------------+-----------------------------+

 


Problem setter: Poitr Rudnicki, University of Alberta, Canada



題目描述:

現在給定有些鍵已經壞了,接下來有一篇文章,問有多少行是好的(即不會存再壞掉的)。

而在這情況下,還有可能再壞幾個鍵?

題目解法:

特別小心 eNd, END, end, enD, ... 等的輸入。

當你處理無視大小寫的時候,同時 "END" 也算文章中的一部分。

#include <stdio.h>
#include <string.h>
using namespace std;

char tolower(char c) {
    if(c >= 'A' && c <= 'Z')
        c = c-'A'+'a';
    return c;
}
int main() {
    puts("+----------+----------------+-----------------------------+");
    puts("| Keyboard | # of printable | Additionally, the following |");
    puts("|          |      lines     |  letter keys can be broken  |");
    puts("+----------+----------------+-----------------------------+");
    char brokenkeys[1005], lines[1005];
    int i, j, k;
    int cases = 0;
    while(gets(brokenkeys)) {
        if(!strcmp(brokenkeys, "finish"))
            break;
        int printable = 0;
        int mapped[128] = {};
        int cannotbroken[128] = {};
        for(i = 0; brokenkeys[i]; i++) {
            brokenkeys[i] = tolower(brokenkeys[i]);
            mapped[brokenkeys[i]] = 1;
            cannotbroken[brokenkeys[i]] = 1;
        }
        while(gets(lines)) {
            int endflag = 0;
            if(!strcmp(lines, "END"))
                endflag = 1;
            int flag = 1;
            for(i = 0; lines[i]; i++) {
                lines[i] = tolower(lines[i]);
                if(mapped[lines[i]] == 1) {
                    flag = 0;
                }
            }
            if(flag) {
                printable++;
                for(i = 0; lines[i]; i++)
                    cannotbroken[lines[i]] = 1;
            }
            if(endflag)
                break;
        }
        printf("|   %3d    |      %3d       | ", ++cases, printable);
        for(i = 'a', j = 0; i <= 'z'; i++)
            if(cannotbroken[i] == 0)
                putchar(i), j++;
        while(j < 28)   putchar(' '), j++;
        puts("|");
        puts("+----------+----------------+-----------------------------+");
    }
    return 0;
}
/*
Xyz
We will work with a basic time unit of an eighth-note. At any
given time, your left foot and right foot will each be on distinct
arrows. Only one foot may perform an action (changing arrows and/or
tapping) during any time unit; jumping is not allowed. Also, you must
remain facing forward in order to see the screen. This puts
limitations on which feet you can use to hit which arrows. Finally,
hitting two arrows in a row with the same foot ("double-tapping") is
exhausting, because you can't shift your weight onto that
foot. Ideally, you want to alternate feet all the way through a string
of consecutive arrows.
END
*/

台長: Morris
人氣(1,811) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][字串] 10875 - Big Math
此分類上一篇:[UVA][greedy+字串] 10333 - The Tower of ASCII

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