10082 - WERTYU

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

Moderator: Board moderators

Yarin
Problemsetter
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume
Contact:

Post by Yarin »

You must declare it like this:
const char check[]= "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./ nn";
Remember that \ has a special meaning in strings!
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Thanks

Post by Ming Han »

Thanks a lot.

I got Accepted now.

That previos wrong code worked on Borland Turbo c++ 3.0 for some unknown reasons.

Ming Han
:: HanWorks ::
haaaz
New poster
Posts: 29
Joined: Sun Sep 08, 2002 8:02 am

Post by haaaz »

Yarin wrote:You don't seem to handle the new line character! It should also be echoed.
Thank you for the hint. I got AC now.
powerboy
New poster
Posts: 8
Joined: Mon May 12, 2003 6:13 am
Contact:

10082 O.L why???

Post by powerboy »

why do i get output limited exceeded
Output Limit Exceeded (OL): Your program tried to write too much information. This usually occurs if it goes into a infinite loop


#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

[cpp]
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
char array [128];

int i;

for (i = 0; i < 128; i++)
array = 0;

array [' '] = ' ';
array ['\n'] = '\n';
array['\''] = '\'';
array['1'] = '\'';
array['2'] = '1';
array['3'] = '2';
array['4'] = '3';
array['5'] = '4';
array['6'] = '5';
array['7'] = '6';
array['8'] = '7';
array['9'] = '8';
array['0'] = '9';
array['-'] = '0';
array['='] = '-';

array['W'] = 'Q';
array['E'] = 'W';
array['R'] = 'E';
array['T'] = 'R';
array['Y'] = 'T';
array['U'] = 'Y';
array['I'] = 'U';
array['O'] = 'I';
array['P'] = 'O';
array['['] = 'P';
array[']'] = '[';
array['\\'] = ']';

array['S'] = 'A';
array['D'] = 'S';
array['F'] = 'D';
array['G'] = 'F';
array['H'] = 'G';
array['J'] = 'H';
array['K'] = 'J';
array['L'] = 'K';
array[';'] = 'L';
array['\''] = ';';


array['X'] = 'Z';
array['C'] = 'X';
array['V'] = 'C';
array['B'] = 'V';
array['N'] = 'B';
array['M'] = 'N';
array[','] = 'M';
array['.'] = ',';
array['/'] = '.';

char character;

while (scanf("%c", &character))
{
if (array[character] != 0)
{
printf("%c", array[character]);
}
}
return 0;
}
[/cpp]
Last edited by powerboy on Tue Jul 01, 2003 10:22 pm, edited 2 times in total.
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

consider the following code segment


while (cin >> num)
{
if (num > 1)
{
array = new bool[num];

instead of allocating memory dynamically, just declare it with some known value.
powerboy
New poster
Posts: 8
Joined: Mon May 12, 2003 6:13 am
Contact:

Post by powerboy »

I cannot declare the array like that because num is not a constant.
Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

10082

Post by Zhao Le »

Here is my code, thanks in advance.

[cpp]#include <iostream.h>

int const Max=47;
char S[Max]={"`1234567890-=QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,./"};

int search(char ch)
{
int i;
for(i=0;i<Max;i++)
if(ch==S) break;
return i;
}

void main()
{
char ch;
while(ch=cin.get())
{
if(ch==EOF) break;
//printf("%c",S[search(ch)-1]);
cout<<S[search(ch)-1]<<flush;
}
//cout<<endl;
}
[/cpp]

if(ch==EOF) break
When add this line got WA.
when remove this line got TLE.
AC makes me feels good,
But WA makes me thinks hard.
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

For TLE I recommend you to use while(gets(line)). In this case you'll store the input in array 'line'.
As for your WA, I think your program can't handle whitespaces.
Good Luck!!! :wink: :wink:
Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

#10082

Post by Zhao Le »

Thanks I got AC.

And I think there is no need to use gets()

getchar()will be better & also faster
AC makes me feels good,
But WA makes me thinks hard.
Eva
New poster
Posts: 14
Joined: Thu Apr 10, 2003 11:31 am
Location: Bombay
Contact:

10082 WA

Post by Eva »

I don know why this simple problem getting so tough :oops:

[cpp]
#include<iostream>
#include<string>

using namespace std;


int main()
{
string str = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";

char ch;

while(cin.get(ch))
{
int index = str.find(ch);

if(ch == '\n')
cout << '\n';
else
cout << str[index-1];
}

return 0;
}
[/cpp]
My own quote:

We are here as Adam and Eve were here!
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

From the problem statement:

"Spaces in the input should be echoed in the output."
nbp0204
New poster
Posts: 2
Joined: Tue Nov 08, 2005 3:35 am

10082 WA ~~~help

Post by nbp0204 »

Code: Select all

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{

	char c;
	int num=0;
	string s[4];
	s[0] = "`1234567890-=";
	s[1] = "QWERTYUIOP[]\\";
	s[2] = "ASDFGHJKL;'";
	s[3] = "ZXCVBNM,./";
	
	while(cin.get(c))
	{
                   if (c == EOF) break;
                   if (c != ' ')
                   {   
                       for (int i=0; i<4; i++)
                      {
                         int k = s[i].find(c);
                         if (k != string::npos){
                             cout << s[i][k-1] << flush;
                             break;
                         }
                       }
                    }else{
                       cout << c << flush;
                    }
	}
	return 0;
}
I always got WA with this code. What is the constraint of the c/c++ code?
I am not sure if there is any boundary condition I miss. My file name is
"main.cpp", and I use upload file to submit my code. Could anyone tell me what is wrong with my code? I will appreciate for your help!!
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

You are not handling newlines. For example output of

Code: Select all

O S, GOMR YPFSU/
O S, GOMR YPFSU/
should be

Code: Select all

I AM FINE TODAY.
I AM FINE TODAY.
nbp0204
New poster
Posts: 2
Joined: Tue Nov 08, 2005 3:35 am

Post by nbp0204 »

Thx ~~~ I really forgot to handle the newline char.
Problem solved ~~ Thx for your help.
abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

10082--runtime error

Post by abhi »

Code: Select all

    #include<stdio.h>

int main()
{

long long i;
char a[300],str[1000000],sym;

a['W']='Q';
a['E']='W';
a['R']='E';
a['T']='R';
a['Y']='T'; 
a['U']='Y';
a['I']='U';
a['O']='I';
a['P']='O';
a['[']='P';
a[']']='[';
a['\\']=']';
a[' ']=' '; 
a['1']='`';
a['2']='1';
a['3']='2';
a['4']='3';
a['5']='4';
a['6']='5';
a['7']='6';
a['8']='7';
a['9']='8';
a['0']='9'; 
a['-']='0';
a['=']='-';
a['S']='A';
a['D']='S';
a['F']='D';
a['G']='F';
a['H']='G'; 
a['J']='H';
a['K']='J';
a['L']='K';
a[';']='L';
a['\'']=';'; 
a['X']='Z';
a['C']='X';
a['V']='C';
a['B']='V';
a['N']='B'; 
a['M']='N';
a[',']='M';
a['.']=',';
a['/']='.'; 

  


gets(str);

while (str[i])
	
{
str[i]=sym;

            putchar(a[sym]);
		i++;
}
return 0;
}

i get RE ...... can anyone tell me y ??
Post Reply

Return to “Volume 100 (10000-10099)”