Posted: Fri Jun 22, 2007 5:22 pm
Hi I've been getting Runtime Error (Signal 11) for this problem I was wondering if anyone can tell me what's wrong with my code plz
Code: Select all
removed
Code: Select all
removed
Code: Select all
removed
Code: Select all
if( num1[i]>9 )
{
num1[i]-=10;
i=increase(i+1);
}
Code: Select all
while( num1[i]>9 )
{
num1[i]-=10;
num1[i+1]++;
i++;
}
Code: Select all
#include<stdio.h>
//10013
int main()
{
//freopen("in10013.txt","r",stdin);
int i,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
long num[100][2],sum[100];
long ad=0;
long j,m;
int f=1;
scanf("%ld",&m);
for(j=1;j<=m;j++)
scanf("%ld %ld",&num[j][0],&num[j][1]);
for(j=0;j<=m;j++)
sum[j]=0;
for(j=m;j>=1;j--)
{
f=1;
sum[j]+=num[j][0]+num[j][1];
if(sum[j]/10>0)
{
sum[j-1]=sum[j]/10;
sum[j]=sum[j]%10;
f=0;
}
}
for(j=0+f;j<=m;j++)
printf("%ld",sum[j]);
printf("\n");
printf("\n");
}
return 0;
}
What is wrong with this answer?WR wrote:Your result is really
?Code: Select all
... 6692 < ---- ????
Code: Select all
#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
char a[1000001] = {'\0'}, b[1000001] = {'\0'}, c[1000001] = { '\0' };
int main()
{
int n;
cin >> n;
while( n-- )
{
int x;
cin >> x;
int sum , carry = 0;
carry = 0;
sum = 0;
for( int i = x - 1; i >= 0; i-- )
{
cin >> a[i] >> b[i];
}
for( int i = 0; i < x; i++ )
{
sum = ( a[i] - '0' ) + ( b[i] - '0' ) + carry;
c[i] = ( sum % 10 ) + '0';
if( sum > 9 )
carry = 1;
else
carry = 0;
}
//if( carry == 1 )
//cout << carry;
for( int i = x - 1; i >= 0; i-- )
cout << c[i];
if( n > 0 )
cout << endl << endl ;
}
return 0;
}
Code: Select all
#include<iostream>
#include<math.h>
using namespace std;
main()
{
#ifndef ONLINE_JUDGE
freopen("input","r",stdin);
freopen("output","w",stdout);
#endif
unsigned long N,M,n1,n2;
int x,y,z;
scanf("%lu\n\n",&N);
while(N--)
{
scanf("%lu\n",&M);
n1 = 0;
n2 = 0;
while(--M)
{
scanf("%d %d\n",&y,&z);
n1 = (n1 + y)*10;
n2 = (n2 + z)*10;
}
scanf("%d %d\n",&y,&z);
n1 = n1 + y;
n2 = n2 + z;
printf("%lu\n",n1+n2);
if(N != 0)
{
cout<<endl;
scanf("\n");
}
}
}
Can you tell me why this should be right? Just read the question again. M can be very large. Just make a test case where M = 20, and then check the result yourself. Hope it helps.naffi wrote:can anyone tell me where is the wrong.I tested many sample I/O.
Code: Select all
9 8 7 6
5 3 7 5
---------------+
14 11 14 11
Step by step normalization
14 11 15 1
14 12 5 1
15 2 5 1
Result = 15251