10761 - Broken Keyboard

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

10761 - Broken Keyboard

Post 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
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

10761 - Broken keyboards

Post 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

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

The second output is right.
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post 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.)
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post 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.
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post 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
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post 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.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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...
miras
Learning poster
Posts: 98
Joined: Sat Jun 14, 2003 1:45 pm

Post 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]
Last edited by brianfry713 on Tue Dec 02, 2014 11:42 pm, edited 1 time in total.
Reason: Added code blocks
Remember Never Give Up
Regrads
Miras
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post 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
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

My AC program counts the empty line also.
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
oulongbin
Learning poster
Posts: 53
Joined: Sat Jul 10, 2004 5:57 pm
Location: Shanghai China

10761 - broken keyborad

Post 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]
Last edited by brianfry713 on Tue Dec 02, 2014 11:43 pm, edited 1 time in total.
Reason: Added code blocks
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post 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
Ivo Sluganovic
New poster
Posts: 12
Joined: Tue Sep 21, 2004 10:08 pm

Post 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!
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post by w k »

Hi,

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

Wojciech
Post Reply

Return to “Volume 107 (10700-10799)”