Page 6 of 22
Posted: Tue Jul 20, 2004 6:58 pm
by Blitz
Could you provide an example of taking the input in as such?
10035 WA in C
Posted: Mon Aug 02, 2004 12:28 pm
by Zoe
Hi
I don't know why I got WA.
Please give me some tips.
Thanks!!
This is my code.
[c]
#include <stdio.h>
#define max 1000
main()
{
long N1[max], N2[max];
long fator1[max], fator2[max], tmp;
long aux1[max], aux2[max];
int i, j;
int amount, min[max], d1, d2;
for ( i = 0 ; i < max ; i++ )
{
scanf("%ld %ld", &N1, &N2);
if ( N1 == 0 && N2 == 0 )
{
amount = i;
break;
}
}
for ( i = 0 ; i < amount ; i++ )
{
d1 = 0;
fator1 = 1;
tmp = N1;
while ( tmp != 0 )
{
fator1 = fator1 * 10;
tmp = tmp / 10;
d1++;
}
fator1 = fator1 / 10;
d1--;
for ( j = d1 ; j >= 0 ; j-- )
{
aux1[j] = N1[i] / fator1[i];
N1[i] = N1[i] - aux1[j] * fator1[i];
fator1[i] = fator1[i] / 10;
}
d2 = 0;
fator2[i] = 1;
tmp = N2[i];
while ( tmp != 0 )
{
fator2[i] = fator2[i] * 10;
tmp = tmp / 10;
d2++;
}
fator2[i] = fator2[i] / 10;
d2--;
for ( j = d2 ; j >= 0 ; j-- )
{
aux2[j] = N2[i] / fator2[i];
N2[i] = N2[i] - aux2[j] * fator2[i];
fator2[i] = fator2[i] / 10;
}
tmp = 0;
for ( j = 0 ; j < 10 ; j++ )
{
tmp = tmp + aux1[j] + aux2[j];
if ( tmp >= 10 )
{
min[i]++;
tmp = tmp / 10;
}
else
tmp = 0;
aux1[j] = 0;
aux2[j] = 0;
}
}
for ( i = 0 ; i < amount ; i++ )
{
if ( min[i] == 0 )
printf("No carry operation.\n");
else if ( min[i] == 1 )
printf("1 carry operation.\n");
else
printf("%d carry operations.\n", min[i]);
}
}
[/c]
Posted: Tue Aug 03, 2004 8:22 am
by Zoe
I fixed some wrong and I got AC.
Thanks!!
java rules
Posted: Thu Sep 02, 2004 6:47 pm
by koodeGuru
I have solved it in java. I havent submitted yet. Can some one post the special cases I have to check for? My code is around 104 lines. I am just reading everything as a String and then converting back to integer and then again to string. For a moment I felt this problem as text processing problem. Definitely there is some arithematic involved offcourse.I will let you know people after submitting the problem.
java rules
Posted: Thu Sep 02, 2004 6:48 pm
by koodeGuru
I have solved it in java. I havent submitted yet. Can some one post the special cases I have to check for? My code is around 104 lines. I am just reading everything as a String and then converting back to integer and then again to string. For a moment I felt this problem as text processing problem. Definitely there is some arithematic involved offcourse.I will let you know people after submitting the problem.
10035
Posted: Fri Sep 10, 2004 2:51 pm
by branka
I don't know what is wrong with my problem, I tested it with many numbers and it works fine, but i stil get wrong answer.
Program in JAVA:
Code: Select all
[java]
import java.io.*;
import java.util.*;
class Main{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main(String[] args)
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}
void Begin(){
String input;
StringTokenizer idata;
long st1, st2, prenesi, stej, a, b;
while((input = Main.ReadLn (255)) != null)
{
idata = new StringTokenizer (input);
a = Integer.parseInt(idata.nextToken());
b = Integer.parseInt(idata.nextToken());
prenesi = 0;
stej = 0;
if((a == 0) && (b == 0)){
break;
}
while((a > 0) || (b > 0)){
st1 = a%10;
st2 = b%10;
a = a/10;
b = b/10;
if(st1+st2+prenesi >= 10){
prenesi = 1;
stej = stej + 1;
}
else{
prenesi = 0;
}
}
if(stej > 0){
System.out.println(stej+" carry operations.");
}
else{
System.out.println("No carry operations.");
}
}
}
}
[/java]
I allredy searchd past postings but i didn't find any helpfull information....
Please help
THANKS[/list]
Posted: Fri Sep 10, 2004 10:10 pm
by Ghust_omega
Hi branka when the carry operation is equals to 1 you have to say 1 carry operation no operations
Hope it helps
Keep posting!!
Re: 10035 Error?
Posted: Sun Oct 03, 2004 10:27 am
by jhonny_yang
give space at your all output :
cout << count << " carry operations." << endl;
to
cout << count << " carry operations.<space>" << endl;
but it AC(P.E) my program is P.E too i don't know why ?
Re: 10035 Error?
Posted: Sun Oct 03, 2004 10:29 am
by jhonny_yang
jhonny_yang wrote:give space at your all output :
cout << count << " carry operations." << endl;
to
cout << count << " carry operations.<space>" << endl;
but it AC(P.E) my program is P.E too i don't know why ?
But i'm not change your program and accepted maybe cause of your email. please try at //@END_OF_SOURCE_CODE at your last program
Posted: Sun Oct 03, 2004 10:52 am
by A1
I think every body should always use this
http://acm.uva.es/problemset/submit.php
page for submitting their code.
Posted: Sun Oct 03, 2004 6:47 pm
by jambon_vn
Nothing is wrong with your code. I submit your code and get AC.

The code gets Presentation Error
Posted: Mon Oct 04, 2004 3:19 am
by attel75
I submited the code at online-judge.uva.es and it gets AC, however it gets a Presentation Error at
http://www.programming-challenges.com, can anyone think of why is this? I can't seem to figure it out.
I got a different implementation of my own and I am having the same problem, it gets AC at online-judge.uva.es but Presentation Error at
http://www.programming-challenges.com. Any thoughts?
10035 wrong answer
Posted: Wed Jan 19, 2005 11:02 pm
by PerHagen
hello !
mi code is :
#include <stdio.h>
#include <iostream.h>
int calcula(int arreglo[],int arreglo2[],int n);
int ubica(int num,int arreglo[],int cant);
void main(void)
{ int a[30],b[30],n,m,i,tec,temp;
cin >> n;
for (m=1;m<=n;m++)
{
scanf("%d",&tec);
a[tec-1]=m;
}
while(scanf("%d",&temp)==1)
{
b[temp-1]=1;
for(i=2;i<=n;i++)
{
scanf("%d",&tec) ;
if ((tec-1)!=(temp-1)) b[tec-1]=i;
}
int precio=calcula(a,b,n);
cout << precio <<endl;
}
}
int calcula(int arreglo[],int arreglo2[],int n)
{
int max=-1,i,pos,k,pos2;
for (i=0;i<n;i++)
{
pos=ubica(arreglo2,arreglo,n);
k=i;int consecutivos=0;
while ((0<k) && (0<pos))
{
pos2=ubica(arreglo[pos-1],arreglo2,n);
if (pos2<k)
{
k=pos2;
consecutivos++;
}
pos--;
}
k=i; pos=ubica(arreglo2,arreglo,n);
while ((k<n) && (pos<(n-1)))
{
pos2=ubica(arreglo[pos+1],arreglo2,n);
if (k<pos2)
{
k=pos2;
consecutivos++;
}
pos++;
}
consecutivos++;
if (consecutivos> max ) max=consecutivos;
}
return max;
}
int ubica(int num,int arreglo[],int cant)
{
int encontrado=0,pos=0;
while ((encontrado==0)&& (pos < cant))
{
if (num==arreglo[pos]) encontrado=1;
else pos++;
}
return pos;
}
but is answer wrong ...i don't understand help
Posted: Mon Jan 24, 2005 6:37 pm
by gits
I couldn't even compile your program. First, you must change main() return type to int, and finish main with "return 0;"
After making this change it compiled, but it immediately crashed with Segmentation Fault. That means it didn't even produce output and that you have some invalid memory reference in your code. Look carefully for places where you might be indexing arrays out of their bounds.
Posted: Wed May 18, 2005 3:21 pm
by Jemerson
I got it in Java
Juz for some help try this algorithm:
1. read as int
2. transform the number in an array of digits (2 int arrays for 2 numbers)
3. pick the greatest number of digits between them.
4. for i =0 to greatest, sum the digits of the ith position if > 9 increase the i+1 in any of the arrays and increase the carry counter.
5. print carry information
My code got 60 lines including readLn() method
As someone asked, follow some of the inputs that caused me some trouble.
Input:
9999 1
1 9999
9989 1
9899 1
1 9989
999999999 999999999
000000001 999999999
0 0
Output
4 carry operations.
4 carry operations.
1 carry operation.
2 carry operations.
1 carry operation.
9 carry operations.
9 carry operations.
Good Luck