Page 6 of 11

Posted: Mon Aug 07, 2006 6:17 pm
by vinit_iiita

Code: Select all

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    string str;
    while (getline(cin,str))
    {
          if(!((int)str[0]>47 && (int)str[0]<58))
          {   // int l=0;
               for (int i=str.size();i>=0;i--)
             {
              int t=(int)str[i];
              while (t>0)
              {
                   cout<<t%10;
                   t=t/10;
                 //  l++;
                   }
                   }
                   cout<<endl;
                   }
                   else
                   {
                       vector<char> v;
                       int c=0;
                       while (c<str.size())
                       {
                             if(str[c+1]=='1' || str[c+1]=='2' || str[c+1]=='0')
                             {
                                            
                                            int t=c+2;
                                            int sum=0;
                                            for(int m=t;m>=c;m--)
                                            sum=10*sum+((int)str[m]-48);
                                            
                                            v.push_back((char)sum);
                                            c=c+3;
                                            }
                                            else
                                            {
                                            int t=c+1;
                                            int sum=0;
                                            for(int m=t;m>=c;m--)
                                            sum=10*sum+((int)str[m]-48);
                                           
                                             v.push_back((char)sum);
                                            c=c+2;
                                            } 
                             
                             }
                             for(int d=v.size()-1;d>=0;d--)
                             cout<<v[d];
                             cout<<endl;
                       }
                   }
                   return 0;
                   } 
          
i have got WA although it passes all test cases i could find...
help me out,...

444 please healp me. why wrong answer?

Posted: Thu Aug 17, 2006 3:33 pm
by srabon
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

void deco_der(char *c);
void enco_der(char *c);



void deco_der(char *c)
{
char a[500],b[20],s[500];
int j = 0;
int k,i,l,n;
for (n = strlen (c) - 1; n >= 0; n--) {
s [j] = c [n];
j++;
}
s [j] = '\0';
l=strlen(s);
for(i=0;i<l;i++)
{
if(s=='1')
{
a[0]=s;
a[1]=s[i+1];
a[2]=s[i+2];
k=atoi(a);
printf("%c",k);
i+=2;
}
else
{
b[0]=s;
b[1]=s[i+1];
k=atoi(b);
printf("%c",k);
i+=1;
}
}
cout<<endl;
}


void enco_der(char *c)
{
int l,i,j,m,g,dig,v,z[1000];
l=strlen(c);
v=0;
for(i=0;i<l;i++)
{
int g=0;
m=c;
do
{
dig = m%10;
g=g*10+dig;
m/=10;

}while(m!=0);
z[v]=g;
v++;
}
for(j=v-1;j>=0;j--)
{
cout<<z[j];
}
cout<<endl;
}


int main()
{
int m,n,d;
char c[5000],s[5000];
while(gets(c)!=NULL)
{
d=c[0];

if(d>47&&d<58)
{
deco_der(c);
}
else
{
enco_der(c);
}
}
return 0;
}

[/list]

444 Plz Help me.

Posted: Fri Sep 15, 2006 6:59 pm
by Maverick+
RUNTIME ERROR
I have no idea. Plz Help me..; :o

Code: Select all

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


int main()
{
	char str[810];

	char crt, *tmp;
	int strLength, i, j;
	

	while(1)
	{
		memset(str, 0, sizeof(str));
		fgets(str, 240, stdin);
		str[241] = '\0';
		strLength=strlen(str);
		str[--strLength] = '\0';
		
		if(*str >= '0' && *str <= '9')
		{			
			tmp = (char*)malloc(sizeof(char) * (strLength+1) );

			for(i = 0; i < strLength; i++)
				tmp[i] = str[strLength - i - 1];
			
			tmp[i] = '\0';

			for(i = 0, j = 0; i < strLength ; j++)
			{
				crt = 10 * (*(tmp+i++) - 0x30);
				crt += *(tmp+i++) - 0x30;

				if(crt >= 10 && crt <= 12)
					crt =  10 * crt + *(tmp+i++) - 0x30;

				str[j] = crt;
			}
			str[j] = '\0';
			
		}
		else
		{
			tmp = (char*)malloc(sizeof(char) * strLength * 3 + 1);
					
			
			
			for(i = 0, j = 0; i < strLength; i++)
			{
				crt = str[i];
				if(crt / 100 != 0)
				{
					tmp[j++] = crt / 100 + 0x30;
					tmp[j++] = (crt % 100) / 10 + 0x30;
					tmp[j++] = (crt % 100) % 10 + 0x30;
				}
				else
				{
					crt = str[i];

					tmp[j++] = crt / 10 + 0x30;
					tmp[j++] = crt % 10 + 0x30;
				}
		
			}
			
			tmp[j] = '\0';
			strLength = strlen(tmp);
			for(i = 0; i < strLength; i++)
				str[i] = tmp[strLength - i - 1];
			str[i] = '\0';


		}
		free(tmp);
		printf("%s\n", str);

	}

	return 0;
}

Posted: Fri Sep 15, 2006 9:16 pm
by little joey
There are already many threads for this problem, so please don't create a new one.

Posted: Mon Oct 09, 2006 10:53 pm
by dev_sust
My code generates same output but RTE. why??? :-? kostay assie.......Need ur Help
Thanx in advance


here is my code:



#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#define sz 85
#define sz2 255

void encode(char e[sz],char d[sz2]);
void decode(char e[sz],char d[sz2]);
void rev( char a[sz2], long int ln);
void revo( char a[sz]);

int main(void)
{
char line[sz], enline[sz2];

//freopen("ain.txt","r",stdin);
//freopen("aout2.txt","w",stdout);

//while(scanf("\n%[^\n]", line)==1)
while(gets(line)!=NULL)
{
if(isdigit(line[0]))
{
decode(line,enline);
printf("%s\n", enline);
}

else
{
encode(line,enline);
printf("%s\n", enline);
}

}
return 0;
}



void encode(char e[sz],char d[sz2])
{
long int x, ln, i, j, k, l;
ln=strlen(e);
for(i=0, j=-1;i<ln;i++)
{
x=(long int) e;
l=floor(log10(x))+1;
j=j+l;
k=j;
while(x>0)
{
d[k--]=x%10;
x=x/10;
}

}
l=j+1;
rev(d,l);

}





void decode(char e[sz],char d[sz2])
{
long int ln, i, j, x;
ln=strlen(e);
revo(e);
for(i=0, j=0;i<ln;)
{
if(e=='1')
{
x=(long int) ((e-48)*100+(e[i+1]-48)*10+e[i+2]-48);

d[j++]=x;
i=i+3;
}
else
{
x=(long int) ((e-48)*10+e[i+1]-48);
d[j++]=x;
i=i+2;
}
}
d[j++]=0;

}



void rev( char a[sz2], long int ln)
{
long int lim, i, temp;

for(i=0; i< ln; i++)
a=a+48;

lim=ln/2;
for(i=0; i< lim; i++)
{
temp=a;
a=a[ln-1-i];
a[ln-1-i]=temp;
}


a[ln]=0;
}


void revo( char a[sz])
{
long int lim, i, temp, ln;


ln=strlen(a);
lim=ln/2;
for(i=0; i< lim; i++)
{
temp=a;
a=a[ln-1-i];
a[ln-1-i]=temp;
}


a[ln]=0;
}

444 runtime error help!!!!

Posted: Thu Oct 26, 2006 2:21 pm
by xinmeng
I'm a beginner of C++. I checked all the post about 444. But they seems irrelevent with my problem. Can anyone help me? This is my code

#include <iostream>
#include <string>
using namespace std;

int main(){
int i,j,number,output;
string input,o;
char ch;
string digit="0123456789";
string code="001101201301401501601701801901011111211311411511611711811911021121221";
while (ch=cin.get()){
input=ch;
o="";
while((ch=cin.get())!='\n'){
input+=ch;
}
if (digit.find_first_of(input[0])>=digit.length()){ //message
for (i=input.length()-1;i>=0;i--){
number=input;
if (number<100)
output=(number%10)*10+number/10;
else
output=(number%10)*100+((number%100)/10)*10+number/100;
if (number%10==0) cout<<"0";
if (number==100) cout<<"0";
cout<<output;
}
cout<<endl;
}
else{
while (input!=""){
if (code.find(input.substr(0,3))>code.length()){
number=(input[0]-'0')+(input[1]-'0')*10;
input.erase(0,2);
}
else{
number=(input[0]-'0')+(input[1]-'0')*10+(input[2]-'0')*100;
input.erase(0,3);
}
ch=char(number);
o.insert(0,ch);
}
cout<<o<<endl;
}
}
return 0;
}


the email only says:

Your program has died with signal 6 (SIGABRT). Meaning:

Abort signal from abort()

Before crash, it ran during 0.002 seconds.

And I really don't know what to do. Please help. thank you!

Posted: Thu Dec 21, 2006 3:02 am
by Jemerson
Same problem as him! Also in Java. There's no mistake in my code. I guess there is something wrong with the oficial output.

hugz

Posted: Thu Dec 21, 2006 1:14 pm
by mogers
You should post in existing posts aboute these problems...

I cant help you with java... but in 445, you cant print '\n' in the last output. I mean, the program output doesnt end with newline.

in 444, try this input

Code: Select all

This is a problem from volume four.
One is to write an encoder-decoder program here.
IS THIS A VALID LINE ?
To B or not TO be is the QUESTION.
to B or NOT to B is tautology !
!!!!!!!!!..........?????????

the quick brown fox jumped over the lazy dog :p

79

i must do what i must do !
332311100123611511711901235012361179401911231110012361151171190123501
Try all the silly cases you can think of
this IS a SILLY case :p
21185231015117999239867673738237923383723511501401611
output:

Code: Select all

64411711111201231019017118011118112390111141120123901101801891114112112379235115012351150140148
6410141110140123901794113011114112112341110100111199101001544111010011119901110123011792310161150141191123111611235115012310101197
36239687376723863767566823562338372748233837
64879737483896581823101401611235115012310189239748236111110112341111123662311148
332312130111180111161171179611235115012366231116112348978723411111236623111611
36363636363636363664646464646464646464333333333333333333

21185233011110012312122179801231014016112341110181111123001101211901711601230211112012301191111141189237019950171131123101401611

a

332311100123611511711901235012361179401911231110012361151171190123501
i must do what i must do !
2011112370101150140161123011799923711111121235111015117999231218018015015112310140161123801801792312141148
21185231015117999239867673738237923383723511501401611
this IS a SILLY case :p<--- NO '\n'  

Posted: Thu Dec 21, 2006 4:50 pm
by chunyi81
A reply after more than 3 years. However please check the bug and suggestions forum regarding problem 445. Thanks for the input for problem 444. I will check it out when I have time.

Posted: Sun Jan 07, 2007 4:59 am
by chunyi81
Thanks for the input. My PE code up there crashes for blank lines. But it should have been a WA rather than PE if there had been blank lines in the input?

Posted: Sun Jan 07, 2007 10:28 am
by chunyi81
Ok, I am certain there are extra blank lines at the end of judge input, but not in the middle, as mogers's sample input suggests. Can anyone verify this? Thanks.

444 WA!!! but why??plz Give me some I/O samples

Posted: Sun Apr 01, 2007 1:56 pm
by RED-C0DE
Hello everyone... I'm a novice in C and C++ (and English grammar) please help me about this problem. I tested my code with more than 50 test cases recently at all topics about this problem and get correct Outputs. BUT I STILL GET WA.
but I still get WA.
Can anybody give me some test cases that my code generates wrong output.
here is my code :

Code: Select all

:::.S.O.L.V.E.D:::

Posted: Sun Apr 01, 2007 8:26 pm
by RED-C0DE
Please give me some input/output examples that my code cannot resolve it and I understand where is my mistakes... :-?

Posted: Wed Apr 04, 2007 9:15 am
by rio
Don't open a new thread if there is one already for the problem.

HINT:

Code: Select all

There is a bug in is_In_Set()

Posted: Wed Apr 04, 2007 11:28 am
by RED-C0DE
rio wrote:Don't open a new thread if there is one already for the problem.

HINT:

Code: Select all

There is a bug in is_In_Set()
Hi Rio and tanks 4 ur attention. but I saw all threads about this problem recently and read all of them carefully and check my Algo with some test cases that I saw there and my Algo works correctly with that.

could u explain for me what's WRONG with is_In_Set() sub or give me some test cases that my Algo works WRONG with it.
I can't identify what's wrong with is_In_Set() sub:( .
thanks again.