
10925 - Krakovia
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Don't be stress
you can use my divide function

you can use my divide function
Code: Select all
#include <stdio.h>
int Divide(char hasil[],int F,char out[])
{
int i, j, x;
x=0; i=0;
while(hasil[i])
{
x *= 10;
x += hasil[i++]-'0';
if(x>=F) break;
}
j=0;
do
{
if(x>=F)
{
out[j++] = (x/F)+'0';
x = x%F;
}
else out[j++]='0';
if(hasil[i]=='\0') break;
x *= 10;
x += hasil[i++]-'0';
}
while(1);
out[j]='\0';
return x;
}
int main()
{
char result[10];
int remainder;
remainder = Divide("123",7,result);
printf("result = %s\n",result);
printf("remainder = %d\n",remainder);
}
"Life is more beautiful with algorithm"
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
This input is not correct as the numbers should be at most 10^20.Jemerson wrote:Input:Code: Select all
1 16 17432479801732498109834891047810 1 15 17432479801732498109834891047810
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
Hi all,
I have checked my code with all of the sample input in the board. And get correct ans. But still the program gives wrong ans in UVA. Please help me to locate the bugs in my code.
Please help me
Thanks
ABDULLAH
I have checked my code with all of the sample input in the board. And get correct ans. But still the program gives wrong ans in UVA. Please help me to locate the bugs in my code.
Code: Select all
/*code has been removed
after accepted*/
Thanks
ABDULLAH
Last edited by abdullah<cse du> on Fri Jul 06, 2007 11:09 am, edited 1 time in total.
We were in past, we are in past and we will go in past.
Initialization problem. Initialize upto 'l_max+1'. Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
1. Use l_max+1 to initialize (or to call other functions)
2. Check the following part
3. Check the output format and change your code.
Hope these help.
2. Check the following part
Code: Select all
while(carry)
{
mod=carry%10;
add[i]=mod+'0';
carry/=10;
i++; // You missed this line
}
Hope these help.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
got wa
i get wa.
can any body find my buge?
i cant find it.
thanks
can any body find my buge?
i cant find it.
Code: Select all
#include <iostream>
#include <string>
using namespace std;
string sum(string s1, string s2)
{
string s3;
int l1 = s1.length();
int l2 = s2.length();
int ptr1 = l1 - 1, ptr2 = l2 - 1, q = 0;
while( ptr1 >= 0 || ptr2 >= 0 )
{
if(ptr1 >= 0)
q += s1[ptr1--] - '0';
if(ptr2 >= 0)
q += s2[ptr2--] - '0';
s3 = (char)( q % 10 + '0') + s3;
q /= 10;
}
while( q )
{
s3 = (char)( q % 10 + '0') + s3;
q /= 10;
}
return s3;
}
string div(string s, int n)
{
string s2;
int q = 0;
for(int i = 0;i < s.length();i++)
{
q = q * 10 + s[i] - '0';
s2 += (char)( q / n + '0');
q = q % n;
}
int ptr = 0;
while(ptr < s2.length() - 1 && s2[ptr] == '0')
ptr++;
s2 = s2.substr(ptr, s2.length() - ptr);
return s2;
}
int main()
{
int n, f, test = 1;
while(cin >> n >> f, n || f)
{
if( test > 1)
cout << endl;
string s1 = "0", s2;
for(int i = 0;i < n;i++)
{
cin >> s2;
s1 = sum(s1, s2);
}
string dv = div(s1, f);
cout << "Bill #"<<test++<<
" costs "<<s1<<": each friend should pay "
<<dv<<endl;
}
return 0;
}
Read the description again.
You are printing a blank line between cases. Why?After each test case, you should print a blank line.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- Learning poster
- Posts: 81
- Joined: Wed May 09, 2007 9:59 pm
- Location: (CSE,DU) Dhaka,Bangladesh
10925,WA,ples help
This is my sample input-output,i got WA.
ples help,giving some concept or sample input-output
input:
3 3
5400000000
5400000000
5400000000
3 2
5400000000
5400000000
9000000001
0 0
output:
Bill #1 costs 16200000000: each friend should pay 5400000000
Bill #2 costs 19800000001: each friend should pay 9900000000
Press any key to continue
i don't know whats problem?

ples help,giving some concept or sample input-output
input:
3 3
5400000000
5400000000
5400000000
3 2
5400000000
5400000000
9000000001
0 0
output:
Bill #1 costs 16200000000: each friend should pay 5400000000
Bill #2 costs 19800000001: each friend should pay 9900000000
Press any key to continue
i don't know whats problem?

''I want to be most laziest person in the world''