424 - Integer Inquiry

Moderator: Board moderators

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Code removed after getting accepted
Last edited by mobarak.islam on Tue Jan 22, 2013 3:59 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry RE

For input

Code: Select all

``````100
100
0``````
the output should be:"200\n", you're printing "2\n0\n0\n"
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

@ brianfry713 , I got accepted. Thanks

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 424, Compile ERROR??

CE ! why?

Code: Select all

``````#include<stdio.h>
int main()
{
int i=1,j,k,d,l,l1,l2,sum,carry,max;
char text[101][101];

while(gets(text[i]),text[i][0]!='0')
{
sum=carry=0;
if(i>=2)
{
l1=strlen(text[i-1])-1;
l2=strlen(text[i])-1;

if(l2>l1)
{
//l1=strlen(text[i-1])-1;
//l2=strlen(text[i])-1;

j=max=l2;
//j=l1;
d=l2-l1;
//printf("-%s\n",text[i-1]);
for(k=1; k<=d; k++)
{
l1=strlen(text[i-1])-1;
for(l=l1; l>=0; l--)
{
//printf("%c %c\n",text[i-1][l+1],text[i-1][l]);
text[i-1][l+1]=text[i-1][l];
}
}
for(k=0; k<d; k++)
text[i-1][k]='0';
//printf("%d\n",d);
//printf("-%s\n",text[i-1]);
}
else if(l1>l2)
{
//l1=strlen(text[i-1])-1;
//l2=strlen(text[i])-1;

j=max=l1;
//j=l2;
d=l1-l2;
for(k=1; k<=d; k++)
{
l2=strlen(text[i])-1;

for(l=l2; l>=0; l--)
text[i][l+1]=text[i][l];
}
for(k=0; k<d; k++)
text[i][k]='0';
//printf("+%s\n",text[i]);
}
else
{
l1=strlen(text[i-1]);
l2=strlen(text[i]);

max=l1;
j=l1-1;

}
while(j>=0)
{
//printf("%c %c\n",text[i-1][j],text[i][j]);
if(sum>9)
{
text[i][j]=(sum%10)+'0';
carry=1;
}
else
{
text[i][j]=sum+'0';
carry=0;
}
//printf("%c",text[i][j]);
j--;
}
if(carry==1)
{
for(j=max; j>=0; j--)
text[i][j+1]=text[i][j];
text[i][0]='1';

}
//printf("*%s\n",text[i]);
}
i++;
}
printf("%s\n",text[i-1]);
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424, Compile ERROR??

You can click My Submissions to see the reason for your CE.
#include <string.h>
Check input and AC output for thousands of problems on uDebug!

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

424 - Integer Inquiry. Why RTE???

getting RTE..

my code.

Code: Select all

``````Removed After AC...
``````
Last edited by me33 on Sun Mar 09, 2014 7:42 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry. Why RTE???

Don't use a package.
http://uva.onlinejudge.org/index.php?op ... &Itemid=30
Post in the appropriate forum, volume IV instead of General.
Check input and AC output for thousands of problems on uDebug!

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

Re: 424 - Integer Inquiry. Why RTE???

Thanks brianfry713...

Got AC

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

UVA problem no. 424 WA

Code removed
Last edited by richatibrewal on Sun Jul 20, 2014 6:10 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA problem no. 424 WA

Input:

Code: Select all

``````9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
0
``````
AC output:

Code: Select all

``````999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999900
``````
Check input and AC output for thousands of problems on uDebug!

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

Re: UVA problem no. 424 WA

I am getting the required output

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: UVA problem no. 424 WA

You must increase parameters

Code: Select all

``````char a[100],b[1];
int i=0,k,sum=0,j[100][100]={0},m,f[100]={0},n=0,l,o,p=0,d,max=INT_MIN;
``````
It must be

Code: Select all

``````char a[101],b[2];
int i=0,k,sum=0,j[101][101]={0},m,f[101]={0},n=0,l,o,p=0,d,max=INT_MIN;``````
For all problems make limit of arrays bigger than problems says.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

Re: UVA problem no. 424 WA

Thank u so much. My code is now accepted

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: UVA problem no. 424 WA

It will be good if you remove your code after getting accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Nahian.Sunny
New poster
Posts: 6
Joined: Tue Oct 21, 2014 12:51 pm

Re: 424 - Integer Inquiry

Why i am getting WA each time? i have tried all test cases available...but still it's WA!!! can anyone help plz???????????????

Code: Select all

``````#include <iostream>

using namespace std;

int main()
{
string s;
char a[110];
int i,j,c,b,n=0;
for(i=0;i<110;i++)
a[i]='0';
a[i]=NULL;
while(1)
{
getline(cin,s);
if(s=="0")
break;
if(n<s.size()) n=s.size();
c=0;
for(i=s.size()-1,j=0;i>=0;i--,j++)
{
b=(s[i]-'0')+(a[j]-'0')+c;
if(b>9)
{
c=b/10;
a[j]=(b%10)+'0';
}
else
{
c=0;
a[j]=b+'0';
}
}
if(c>0)
{
while(c!=0)
{
b=(a[j]-'0')+c;
a[j]=(b%10)+'0';
c=(b+c)/10;
j++;
}
}
}
if(a[n]!='0') cout << a[n];
for(i=n-1;i>=0;i--)
cout << a[i];
cout << endl;
return 0;
}``````
Last edited by brianfry713 on Tue Oct 21, 2014 7:35 pm, edited 1 time in total.