Page 2 of 4
Posted: Wed Oct 23, 2002 3:31 pm
by Yarin
You must declare it like this:
const char check[]= "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./ nn";
Remember that \ has a special meaning in strings!
Thanks
Posted: Wed Oct 23, 2002 4:24 pm
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
Posted: Wed Oct 23, 2002 5:00 pm
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.
10082 O.L why???
Posted: Mon Jun 30, 2003 4:33 am
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]
Posted: Mon Jun 30, 2003 12:06 pm
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.
Posted: Mon Jun 30, 2003 2:41 pm
by powerboy
I cannot declare the array like that because num is not a constant.
10082
Posted: Tue Jul 29, 2003 3:03 pm
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.
Posted: Tue Jul 29, 2003 4:53 pm
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!!!

#10082
Posted: Tue Jul 29, 2003 6:00 pm
by Zhao Le
Thanks I got AC.
And I think there is no need to use gets()
getchar()will be better & also faster
10082 WA
Posted: Sun Nov 30, 2003 11:48 pm
by Eva
I don know why this simple problem getting so tough
[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]
Posted: Mon Dec 01, 2003 2:52 am
by gvcormac
From the problem statement:
"Spaces in the input should be echoed in the output."
10082 WA ~~~help
Posted: Tue Nov 08, 2005 3:47 am
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!!
Posted: Wed Nov 09, 2005 6:18 pm
by mamun
You are not handling newlines. For example output of
should be
Posted: Wed Nov 09, 2005 6:56 pm
by nbp0204
Thx ~~~ I really forgot to handle the newline char.
Problem solved ~~ Thx for your help.
10082--runtime error
Posted: Sat Dec 03, 2005 5:15 pm
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 ??