Page 1 of 3

10761 - Broken Keyboard

Posted: Thu Nov 11, 2004 10:51 am
by w k
Hi,

How about blank lines in the text? Shall I count them as a good line or not? For instance:

eN
E
n

;
END
finish

Is this output correct:

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

or it should rather be:
+----------+----------------+-----------------------------+
| Keyboard | # of printable | Additionally, the following |
| | lines | letter keys can be broken |
+----------+----------------+-----------------------------+
| 1 | 1 | abcdfghijklmopqrstuvwxyz |
+----------+----------------+-----------------------------+


Wojciech

10761 - Broken keyboards

Posted: Thu Nov 11, 2004 11:31 am
by w k
Hi,

How about blank lines in the text? Shall I count them as a good line or not? For instance:

eN
E
n

;
END
finish

Is this output correct:

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

or it should rather be:
+----------+----------------+-----------------------------+
| Keyboard | # of printable | Additionally, the following |
| | lines | letter keys can be broken |
+----------+----------------+-----------------------------+
| 1 | 1 | abcdfghijklmopqrstuvwxyz |
+----------+----------------+-----------------------------+


Wojciech


Posted: Thu Nov 11, 2004 3:32 pm
by Krzysztof Duleba
The second output is right.

Posted: Thu Nov 11, 2004 4:20 pm
by misof
IMHO the first output is correct. You can type a blank line with any set of broken letters. (You can also type any other line with only non-alphabetic characters.) My program giving this output is AC.

Anyhow, probably there is no such test case... (I assume Krzysztof also has AC with a program giving the opposite answer.)

Posted: Thu Nov 11, 2004 5:18 pm
by Krzysztof Duleba
Ups, misof is right. I didn't copy this test case carefully enough and at the end of some lines (including the first one) a space was added. That made my code work as if spacebar was broken (I don't check if broken keys are letters), hence the output. Without those spaces the right output is 1 2.

Posted: Thu Nov 11, 2004 10:55 pm
by w k
Thanks,

At least one thing is clear. I still can't find a mistake in my program. Do You have any hint? Or interesting I/O?

Wojciech

Posted: Fri Nov 12, 2004 10:19 am
by misof
The only special case I can think of is when there are no printable lines, i.e.

Code: Select all

abcde
aaaaa
bbbbb
C C C C C
ddddd
END
finish
when the output should be

Code: Select all

+----------+----------------+-----------------------------+
| Keyboard | # of printable | Additionally, the following |
|          |      lines     |  letter keys can be broken  |
+----------+----------------+-----------------------------+
|     1    |        0       | fghijklmnopqrstuvwxyz       |
+----------+----------------+-----------------------------+
Also check for stupid typos in the output and check whether you are formatting the result properly when there are more than 9 keyboards/printable lines.

Posted: Fri Nov 12, 2004 11:44 am
by little joey
Be sure to print spaces (ASCII 0x20) in the output. The HTML of the problem statement contains high ASCII (0xA0) that look like spaces, but will lead to WA if you copy it into your output statements. I had this problem during the contest and couldn't figure out why I had WA until I looked at my source code with a hex-editor.

Shahriar Manzoor who edits most of the problem statements nowadays, seems to use some kind of MickyMouse editor to build the HTML-pages. Apart from looking terrible in any non-IE browser, the source text of the pages contain all kinds of non-standard crap characters which can lead to unexpected errors. Although UVA runs on Linux and pretends to be W3C compliant on their main page, Microsoft is creaping in steadily...

Posted: Fri Nov 12, 2004 11:50 am
by miras
hear is my code... can u tell me what is wrong hear ??
[pascal]

Code: Select all

var wc,t,s,break:string;
    keyboard,printable,a:longint;
    dodatkowe:array['A'..'Z'] of boolean;
    finito,koniec,niemoze:boolean;
    x:char;


procedure zeroo;
 begin
 wc:='';
 t:='';
 s:='';
 break:='';
 for x:='A' to 'Z' do dodatkowe[x]:=false;
 printable:=0;
 finito:=false;
 niemoze:=false;
 end;


function nalezy(x:char):boolean;
 begin
 if ((ord(x)>96) and (ord(x)<123)) or
    ((ord(x)>64) and (ord(x)<91))
    then nalezy:=true else nalezy:=false;
 end;




procedure read_data;
begin
koniec:=false;
 readln(s);
if s='finish' then koniec:=true;
if koniec=false then
begin
 for a:=1 to length(s) do
 break:=break+upcase(s[a]);
 for a:=1 to length(break) do
  dodatkowe[break[a]]:=true;

 repeat
  readln(t);
   s:='';

   for a:=1 to length(t) do
    if nalezy(t[a]) then s:=s+upcase(t[a]);

 niemoze:=false;
if length(s)>0 then
 begin
 for a:=1 to length(break) do
  if pos(break[a],s)>0 then niemoze:=true;
 end;

if (niemoze=false) and (length(t)>0) then
 begin
  inc(printable);
  for a:=1 to length(s) do
  dodatkowe[s[a]]:=true;
 end;
 if length(s)>2 then
  if (s[1]='E') and (s[2]='N') and (s[3]='D') then finito:=true;
 until finito;
write('|');
inc(keyboard);
write(keyboard:6);
write('|':5);
write(printable:9);
write('|':8);

 for x:='A' to 'Z' do
  if dodatkowe[x]=false then wc:=wc+chr(ord(x)+32);
write(' ',wc);
writeln('|':26-length(wc)+3)
end;
end;



begin
writeln('+----------+----------------+-----------------------------+');
writeln('| Keyboard | # of printable | Additionally, the following |');
writeln('|          |      lines     |  letter keys can be broken  |');
writeln('+----------+----------------+-----------------------------+');


repeat
zeroo;
read_data;
if koniec=false then
writeln('+----------+----------------+-----------------------------+');

until koniec;

writeln;
end.






[/pascal]

Posted: Fri Nov 12, 2004 1:48 pm
by w k
Hi,

For output I use:

printf("|%6hd |%9hd | %-28s|\n",klaw,nl,uz);
printf("+----------+----------------+-----------------------------+\n");

Is it wrong?

By the way. Where can I find hex editor?

Wojciech

Posted: Thu Nov 18, 2004 7:17 pm
by ..
My AC program counts the empty line also.

10761 - broken keyborad

Posted: Sat Nov 20, 2004 4:14 am
by oulongbin
i have passed any samples,why i always got WA?
[cpp]

Code: Select all

#include <iostream>
using namespace std;
#include <cstdio>
#include <cstring>

int  main()
{
    bool key[26],key2[26];
    bool f;
    char brokenkey[26];
    char line[100];
    int i;
    int len;
    int c=1;
    int num;
    int temp;
    cout<<"+----------+----------------+-----------------------------+"<<endl;
    cout<<"| Keyboard | # of printable | Additionally, the following |"<<endl;
    cout<<"|          |      lines     |  letter keys can be broken  |"<<endl;
    cout<<"+----------+----------------+-----------------------------+"<<endl;
    while(cin.getline(brokenkey,26))
    {
        if(!strcmp(brokenkey,"finish"))
                break;
        for(i=0;i<26;i++)
        {
            key[i]=true;
            key2[i]=true;
        }    
        num=0;
        f=false;
        temp=0;
        len=strlen(brokenkey);
        for(i=0;i<len;i++)
        {
            if(brokenkey[i]>='A'&&brokenkey[i]<='Z')
                        brokenkey[i]=char(int(brokenkey[i])+32);
        }    
        for(i=0;i<len;i++)
        {
            key[brokenkey[i]-97]=false;
            key2[brokenkey[i]-97]=false;
        }    
        while(cin.getline(line,1000))
        {
            if(!strcmp(line,"END"))
                        f=true;
            len=strlen(line);
            for(i=0;i<len;i++)
            {
                if(line[i]>='A'&&line[i]<='Z')
                        line[i]=char(int(line[i])+32);
            }
            for(i=0;i<len;i++)
            {
                if(line[i]>='a'&&line[i]<='z')
                if(key[int(line[i])-97]==false)
                                break;
            }        
            if(i==len)
            {
                 num++;
                 for(i=0;i<len;i++)
                 {
                     key2[int(line[i])-97]=false;
                 }    
            }    
            if(f)
            break;
        } 
        printf("|%6d    |%9d       | ",c++,num);
        
        for(i=0;i<26;i++)
        {
            if(key2[i])
            {cout<<char(i+97);
            temp++;}
        }    
        for(i=0;i<28-temp;i++)
        cout<<" ";
        cout<<"|"<<endl;
        cout<<"+----------+----------------+-----------------------------+"<<endl;
    }    
    return 0;
}    
[/cpp]

Posted: Sat Nov 20, 2004 11:38 pm
by w k
I checked with hex editor that
printf("|%6hd |%9hd | %-28s|\n",klaw,nl,uz); gives correct output, that means the only white characters used are spaces and newline - at least on my computer. Do You think that on judge system might be different? Other words: Is it possible that on judge system such command output could use other white characters?

Wojciech

Posted: Thu Dec 02, 2004 12:40 pm
by Ivo Sluganovic
I struggled a lot because I used to transform all characters into lowercase and then check for "finish" and "end".
This is wrong and there is surely an input that checks this.
Maybe this is your problem!

Posted: Thu Dec 02, 2004 9:33 pm
by w k
Hi,

Unfortunately not. These cases I handle correctly. I'm still struggling with this problem.

Wojciech