Page 7 of 11
Posted: Wed Apr 04, 2007 3:18 pm
by rio
HINT
Manpage of atoi():
NAME
atoi, atol, atoll, atoq - convert a string to an integer
SYNOPSIS
#include <stdlib.h>
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
long long atoq(const char *nptr);
DESCRIPTION
The atoi() function converts the initial portion of the string pointed
to by nptr to int.
Posted: Thu Apr 05, 2007 11:35 am
by RED-C0DE
Tanks Rio. I got AC

. I didn't use atoi function and wrote a function to get Numeric Value of a string myself. so I have 1 question again>>:
Is better that we using standard functions of C , C++ or write them ourself?
my answer now is : We should writing functions that we need
ourself. and how about U?
Runtime Error
Posted: Sun May 06, 2007 7:44 am
by ranacse05
Here is my code plz tell me why i getting RE?
Code: Select all
[color=green]#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
int i,j,x,y;
char a[81];
while(gets(a))
{
int ln=strlen(a);
if(isdigit(a[0]))
{
for(i=ln-2;i>=0;i=i-2)
{
char b[4]={0};
if((a[i]-'0')<3)
{
b[1]=a[i];
b[0]=a[i+1];
b[2]=a[i-1];
i--;
}
else
{
b[1]=a[i];
b[0]=a[i+1];
}
x=atoi(b);
printf("%c",x);
}
}
else
{
for(j=ln-1;j>=0;j--)
{ x=a[j];
for(i=0;;i++)
{ y=x%10;
//if(y!=0)
printf("%d",y);
x=x/10;
if(x==0)
break;
}
}
}
printf("\n");
}
return 0;
}[/color]
PE
Posted: Fri May 18, 2007 4:21 pm
by sfelixjr
i got presentation error, but this problem output is very simple, i cant see where my mistake is, does anybody here can help me?
444(WA)
Posted: Wed Jul 18, 2007 3:25 pm
by ishtiaq ahmed
I have tested all the input of the board and and matched the output. Why i am facing WA. Plz help me
Posted: Tue Jul 24, 2007 8:41 am
by RC's
I got RE for this problem.. What's wrong with my code ?
I got AC already
Hm... I wonder why it was runtime error when I declared the array size for input = 85 and output = 255... I increased both of them to 1000 and got AC..
The maximum of spy message is 80, right ? so it's minimum size is 81
so the maximum output should be 80 * 3 = 240, so it's minimum size is 241...
444 Encode Decode Getting Wrong Answer
Posted: Fri Feb 01, 2008 1:11 pm
by mirage
hi friends,
I m gettin wrong answer for this problem but can't figure out why....
Tried various inputs but works for all of them....
Is thr any special input???
Plz help
here's the code...
Code: Select all
//encoder and decoder
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
while(getline(cin,s,'\n')){
//check category
int i=s.length()-1;
int val=s[i]-'0';
if(val>=0 && val<=9){
//this is the encoded one decode it
i=s.length()-1;
while(i>0){
int j=int(s[i--]-'0')*10+int(s[i--]-'0');
if(j<33) j=j*10+int(s[i--]-'0');
cout<<char(j);
if(s[i]==' ') i=0;
}
}
else{
i=s.length()-1;
while(i>=0){
int temp=int(s[i]);
if(temp<100){
cout<<temp%10<<int(temp/10);
}
else cout<<temp%10<<int(temp/10)%10<<int(temp/100);
i=i-1;
}
}
cout<<"\n";
}
return(0);
}
[/code]
Posted: Sun Feb 03, 2008 5:52 pm
by mirage
hi friends,
I m gettin wrong answer for this problem but can't figure out why....
Tried various inputs but works for all of them....
Is thr any special input???
Plz help
here's the code...
Code: Select all
//encoder and decoder
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
while(getline(cin,s,'\n')){
//check category
int i=s.length()-1;
int val=s[i]-'0';
if(val>=0 && val<=9){
//this is the encoded one decode it
i=s.length()-1;
while(i>0){
int j=int(s[i--]-'0')*10+int(s[i--]-'0');
if(j<33) j=j*10+int(s[i--]-'0');
cout<<char(j);
if(s[i]==' ') i=0;
}
}
else{
i=s.length()-1;
while(i>=0){
int temp=int(s[i]);
if(temp<100){
cout<<temp%10<<int(temp/10);
}
else cout<<temp%10<<int(temp/10)%10<<int(temp/100);
i=i-1;
}
}
cout<<"\n";
}
return(0);
}
strange
Posted: Thu Feb 07, 2008 7:58 pm
by gvs
Hi all,
can anybody help me?
I have tested my code for all the I/O posted on the board, yet the OJ is givin me WA.
It is really frustrating.
Can anybody please help?
Posted: Sat Feb 09, 2008 11:12 am
by AcmNightivy
my god..this code give the correct ans i found..and i have considered the range of the array..but it change from WA to RE..and till now..I only correct one code..depressed..help..
Code: Select all
#include <iostream.h>
#include <stdio.h>
#include "string.h"
void Encode (char str[])
{
int i, loop, count;
char result[241];
int temp;
count = 0;
for (i = 0; str[i] != '\0'; i++)
{
temp = (int)str[i];
if (temp >= 100)
loop = 3;
else
loop = 2;
if (loop == 2)
{
result[count++] = temp / 10 + 48;
result[count++] = temp % 10 + 48;
}
else
{
result[count++] = temp / 100 + 48;
temp = temp % 100;
result[count++] = temp / 10 + 48;
result[count++] = temp % 10 + 48;
}
}
count--;
while (count >= 0)
cout<<result[count--];
cout<<endl;
}
void Translate (char str[])
{
int i;
int count;
count = 0;
for (i = strlen (str) - 1; i >= 0; i--)
{
count = count * 10 + str[i] - 48;
if ((count >= 65 && count<= 122) || count == 32
|| count == 33 || count == 44 || count == 46
|| count == 58 || count == 59 || count == 63)
{
cout<<(char)count;
count = 0;
}
}
cout<<endl;
}
int main ()
{
char str[82];
while (gets (str))
{
if (str[0] > '9' || str[0] < '0')
Encode (str);
else
Translate (str);
}
return 0;
}
444 Wrong Answer (Java)
Posted: Wed Apr 02, 2008 5:52 pm
by murad357
Hello Friends,
I know this is a very easy problem. But looks like I am missing something here. I am getting WA for this code, while I have tested all the sample input given in this forum. Any help will be appreciated. (I also tried this with BufferedReader instead of Scanner).
Note: I have two other static method reverse and isDigit which I didn't include in this code
Code: Select all
public static void main (String args[]) throws IOException // entry point from OS
{
Scanner in = new Scanner (System.in);
try
{
while (in.hasNext())
{
String str = in.nextLine();
String temp="",tmp="";
if (str == null) // end of file reached
break;
else
{
if (isDigit(str.charAt(0)))
{
temp = reverse(str);
for (int i=0; i< temp.length();)
{
String t= temp.substring(i);
if (t.charAt(0) == '1')
{
i+=3;
char chr = (char) Integer.parseInt(t.substring(0,3));
tmp+=chr;
}
else
{
i+=2;
char chr = (char) Integer.parseInt(t.substring(0,2));
tmp+=chr;
}
}
System.out.println(tmp);
}
else
{
for (int i=0; i<str.length();i++)
{
int car = str.charAt(i);
temp+=car;
}
temp = reverse(temp);
System.out.println(temp);
}
} // end try
}// end while
}
catch (Exception e)
{
System.exit(0);
}
}// End Main
Re: 444 Wrong Answer (Java)
Posted: Sun Apr 06, 2008 11:11 am
by Jan
Search the board first. Don't open a new thread if there is one already.
444 - WA
Posted: Wed May 21, 2008 6:31 pm
by zyxw
I cant find where i'm wrong
i have checked all the sample i/p in this thread and the following threads:
http://online-judge.uva.es/board/viewto ... =7844#wrap
http://online-judge.uva.es/board/viewto ... 66b4e#wrap
i get exactly same o/p as mentioned in above threads...
so i present my code here...
Code: Select all
#include<iostream> // acm-444
#include<vector>
#include<cctype>
using namespace std;
#define pb push_back
#define sz size()
void encode(string s)
{
string ans="";
for(int i=s.sz-1; i>=0; i--)
{
char* t1=new char;
int a = (int) s[i];
sprintf(t1,"%d",a);
string t="";
for( int j=0; t1[j]!='\0'; j++ )
{
t+=t1[j];
}
reverse(t.begin(),t.end());
ans+=t;
}
cout<<ans<<endl;
}
void decode(string s)
{
string ans="";
for(int i=s.sz-1; i>=0; )
{
string t="";
t+= s[i];
t+= s[i-1];
int a=0;
sscanf(t.c_str(),"%d",&a);
if( (a>=65 && a<=90) || (a>=97 && a<=122) || (a==32) || (a==33) || (a==44) || (a==46) || (a==58) || (a==59) || (a==63) )
{
i-=2;
ans+= (char) a ;
}
else
{
t+=s[i-2];
i-=3;
a=0;
sscanf(t.c_str(),"%d",&a);
ans+= (char) a ;
}
}
cout<<ans<<endl;
}
int main()
{
string s;
while( !cin.eof() )
{
getline(cin,s);
if(s=="")
printf("\n");
else if( isalpha(s[0]) || (s[0]==' ') || (s[0]=='!') || (s[0]==',') || (s[0]=='.') || (s[0]==':') || (s[0]==';') || (s[0]=='?') )
encode(s);
else
decode(s);
}
}
Somebody pls help

Re: Why #444 WA?
Posted: Sat May 31, 2008 4:08 pm
by hasib_bd
Following considerations may help to avoid WA for this problem.
1. Consider the array size at least to hold 80 * 3(if the ASCII is >= 100) + 1(Null char)= 2401 characters.
2. Consider the reverse of 100 (for d) as 001 and same for others ending with 0.
3. Consider that there may be empty line in the Input. For those empty line you must also print an empty line. (I was getting WA because i wasn't printing anything when there was an empty line in the input.
Hope it might help.
Re: Why #444 WA?
Posted: Mon Jun 16, 2008 9:15 pm
by palash
pls help, every time i got WA with my code. here is my code