10464 - Big Big Real Numbers

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
route
New poster
Posts: 39
Joined: Sat Dec 21, 2002 1:25 am

10464 - Big Big Real Numbers

Post by route »

Can I have Some special cases for it ?
User avatar
saiqbal
New poster
Posts: 36
Joined: Wed Aug 07, 2002 4:52 pm
Location: Dhaka, Bangladesh
Contact:

Post by saiqbal »

all the special cases are included in the sample i/o i think. :)

good luck
-sohel

ps- don't forget about the length of a number :wink:
afonsocsc
New poster
Posts: 34
Joined: Mon Mar 24, 2003 1:15 am
Location: Portugal, Lisbon

Post by afonsocsc »

input:

Code: Select all

25
1111.332 1123.1112
.223 9.8963
0.002331 .0012
1111.20000 1.0000
004112.000 21.00
.123 .001
3.333 -1.111
-1.111 3.333
.  .
0.  .0
000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000.
. 62457.73682
9999.999999 00000000000000000000000000000000000000000.000001
3.3 6.6
4.00000000000000000000000000000000000000000000000000000000000000000000000000004 5.00000000000000000000000000000000000000000000000000000000000000000000000000006
0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
-1.0 -2.1
-11111111111111111111111111111111111111.111111111111111111111111111111 11111111111111111111111111111111111111.111111111111111111111111111111
421.652 -9876.0
-00000000000000000000000000000000351.542 000000000000000000000000000000000000000000000000000000000000000000000000000000000000351.5423
-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000351.54230 00000000000000000000000000000000000000351.5423
-351.54231 351.5423
-9999.632 1.543
-.5 5.
-0. -0.
output:

Code: Select all

2234.4432
10.1193
0.003531
1112.2
4133.0
0.124
2.222
2.222
0.0
0.0
0.0
62457.73682
10000.0
9.9
9.0000000000000000000000000000000000000000000000000000000000000000000000000001
1.0
-3.1
0.0
-9454.348
0.0003
0.0
-0.00001
-9998.089
4.5
0.0
razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Location: SUST,BANGLADESH
Contact:

Finally I got it right

Post by razibcse »

I am getting RTE for this..I couldn't figure out why...
please help me to find my mistake..I have matched all the answers in the special cases given here....
are extra spaces there in the input number?The problem says:
First line of the input is a non negative integer N. Next N line follows a pair of real numbers separated by a space in each line. Negative real number can appear in the input. Length of each number can be 1000 digits both before and after decimal point. The Input ends at EOF.
how come first N and then EOF?
here's my code:

Code: Select all

I got AC...so the code is deleted..
Last edited by razibcse on Fri Apr 25, 2003 8:39 pm, edited 1 time in total.
Wisdom is know what to do next; virtue is doing it.
route
New poster
Posts: 39
Joined: Sat Dec 21, 2002 1:25 am

Post by route »

I think it's not the problem of spaces.Even with more than one space, they will be ignored automatically .
sweko
New poster
Posts: 7
Joined: Fri Apr 19, 2002 4:05 pm

Post by sweko »

I get all the test cases correct, but still get WA.
Any other special cases that may exist?
SWeko has spoken
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

10464

Post by mohiul alam prince »

hi

i am getting WA in this problem
please check my input and output

INPUT

Code: Select all

26

000000000000000000000000000000000000000001.000000000000000000000000000000001
00000000000000000000000000000000000000000000000000000000000000000000000000000000000.0 

-100000000000000000000000000000000005454534545435453765454545454542454545454545.545485454545 -5454534354534.000000000000000000000000000000000000000000000000000000000000000000000000000001

0.0 
0.0

-0.0
-0.0

-0.0
0.0

.000000000000000000000000000001               
00000000000000.000000000000000000000

0000000000000000000000000000000000000000000000000.000000000000000000000000000   
.000000000000019

77777777777777777777777777777777777777777777777777777777777777777777777777777.9999999999999999
-77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777.8888

77777777777777777777777777777777777777777888888888888888888888888880000000000000000000009.11111
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.000009

-4444444444444444444444.123400000000000000000000000000 
-777777777777777777777.5685

0000000000000000000000000000000000000000000000001.0
111111111111111111111111111111111111111111111111111.

.0000000000000000000000000000000000000000000000001
.0000000000000000000000000000000000000000000000009

77777777777777777777777777777777777777777777777777.
.77777777777777777777777777777777777777777777777777

-77777777777777777777777777777777777777777777777777.
.77777777777777777777777777777777777777777777777777

77777777777777777777777777777777777777777777777777.
-.77777777777777777777777777777777777777777777777777

-77777777777777777777777777777777777777777777777777.
-.77777777777777777777777777777777777777777777777777

25 
25

25. 
.25

55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555559999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997777777777777777777777777777777777777777777777777777777777777777777777777777777755555555555555555555555555555555555000000000000000000000000000000000000000000000000000000000055555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333.111111111111111111111111111111111111100000000000000000000000000000000000000000000009
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

-1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999888888888888888888888888888888888888888888888888888888888888888888888888888

-2222222222222222222222222222222222222222
-88888888888888888888888888888888888888888888888888888888888888888888888888.22222222222222233333

7777777777777777777777777777777777777777777777777777777777777777777777777777777874544444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444499999999999999999999999999999999999999999999999999999.00000000000000000000000000000000000000000000000000078
45.000000000123456

0000000000000000000000000000000000000000000000000000000000000000000000.0000000000000009
111111111111111111111111111111111111111111111111111111111111111111111199999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998888888888888888888

12.23000000000000000000000000000000 
-7899242124121212.524545454545454454545454545454545454545454

123456789.123456789 
-123456789.

-111111111111111111111111111111111111111111111111111111.99999999999999999999999999999
-88888888888888888888888888888888888888888888888888888888.9999999999999999999999999999
OUTPUT

Code: Select all

1.000000000000000000000000000000001
-100000000000000000000000000000000005454534545435453765454545454547909079809079.545485454545000000000000000000000000000000000000000000000000000000000000000001
0.0
0.0
0.0
0.000000000000000000000000000001
0.000000000000019
-77777777777699999999999999999999999999999999999999999999999999999999999999999999999999999.8888000000000001
88888888888888888888888888888888888888888999999999999999999999999991111111111111111111120.111119
-5222222222222222222221.6919
111111111111111111111111111111111111111111111111112.0
0.000000000000000000000000000000000000000000000001
77777777777777777777777777777777777777777777777777.77777777777777777777777777777777777777777777777777
-77777777777777777777777777777777777777777777777776.22222222222222222222222222222222222222222222222223
77777777777777777777777777777777777777777777777776.22222222222222222222222222222222222222222222222223
-77777777777777777777777777777777777777777777777777.77777777777777777777777777777777777777777777777777
50.0
25.25
55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555559999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997777777777777777777777777777777777777777777777777777777777777777777777777777777755555555555555555555555555555555555000000000000000000000000000000000000000000000000000000000055555555555555555555555555555555555555555555555555555555555555555555633333333333333333333333333111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110.111111111111111111111111111111111111100000000000000000000000000000000000000000000009000000000099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111112
-88888888888888888888888888888888891111111111111111111111111111111111111110.22222222222222233333
7777777777777777777777777777777777777777777777777777777777777777777777777777777874544444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444500000000000000000000000000000000000000000000000000044.00000000012345600000000000000000000000000000000000078
111111111111111111111111111111111111111111111111111111111111111111111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000089999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998888888888888888888
-7899242124121200.294545454545454454545454545454545454545454
0.123456789
-89000000000000000000000000000000000000000000000000000000.99999999999999999999999999989
thanks
MAP
daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

Your output is correct.
Could you post your code without the ADD/SUBTRACT routines?
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

thank for your reply
Here is my code

Code: Select all

#include <iostream>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <string.h>
#include <stdio.h>

using namespace std;

int mark = 0;

string addition(string a, string b) {
	int i;
	string s;
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (a.length() < b.length()) a.resize(b.size(), '0');
	else b.resize(a.size(), '0');
	int Carry = 0;
	for (i = 0; i < a.size(); i++) {
		int x = (a[i] + b[i]) - (2*48) + Carry;
		if (x >= 10) Carry = 1, x %= 10;
		else Carry = 0;
		s.insert(s.begin() + s.length(), x + 48);
	}
	if (Carry) {s.insert(s.end(), Carry + 48);mark = 1;}
	reverse(s.begin(), s.end());
	return s;
}

string subtract(string a, string b) {
	int i;
	string s="", t="";
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (a.length() < b.length()) a.resize(b.size(), '0');
	else b.resize(a.size(), '0');
	int Carry = 0, x, y = 0;
	for (i = 0; i < a.size(); i++) {
		Carry = (a[i]) < (b[i] + y) ? 10 : 0;
		x = ((Carry + a[i]) - (b[i] + y));
		y = a[i] < (b[i] + y) ? 1 : 0;
		s.insert(s.begin () + s.length (), x + 48);
	}
	if (y) {s.insert(s.begin() + s.length(), y + 48); mark = 1;}
	reverse(s.begin(), s.end());
	return s;
}

int main () {

	int i, Test;
	string s1, s2, s, a, b, apoint, bpoint, c, d;
	//freopen("D:\\in.txt", "r", stdin);
	//freopen("D:\\out.txt", "w", stdout);
	//scanf("%d", &Test);
	cin>>Test;

	while (Test--) {

		cin>>s1>>s2;
		int flag1 = 0, flag2 = 0;
		
		mark = 0;
		for (i = 0; i < s1.length(); i++) if (s1[i] == '-') {flag1 = 1; s1[i] 
= ' ';break;}
		for (i = 0; i < s2.length(); i++) if (s2[i] == '-') {flag2 = 1; s2[i] 
= ' ';break;}
		
		for (i = 0; i < s1.length(); i++) if (s1[i] != '0' && s1[i] != '-') 
{if (i >= 0 && s1.length() >= i)s1.erase(s1.begin(), s1.begin() + 
i);break;}
		
		for (i = 0; i < s2.length(); i++) if (s2[i] != '0' && s2[i] != '-') 
{if (i >= 0 && s2.length() >= i)s2.erase(s2.begin(), s2.begin() + 
i);break;}
		
		int e1 = 0, e2 = 0, f1 = 0, f2 = 0;
		for (i = 0; i < s1.length(); i++) if (s1[i] == '.') {s1[i] = ' '; e1 
= 1;break;}
		for (; i < s1.length(); i++) if (isdigit(s1[i])) { f1 = 1;break;}
		for (i = 0; i < s2.length(); i++) if (s2[i] == '.') {s2[i] = ' '; e2 
= 1;break;}
		for (; i < s2.length(); i++) if (isdigit(s2[i])) { f2 = 1;break;}

		char a1[5024], a2[5024], a3[5024];
		a1[0] = a2[0] = NULL;
		a = b = apoint = bpoint = "";
		sprintf(a3, "%s", s1.c_str());
		sscanf(a3, "%s %s", a1, a2);
		if (strlen(a1) && strlen(a2))a = a1, apoint = a2;
		else if (strlen(a1) && f1) apoint = a1;
		else a = a1;
		
		a1[0] = a2[0] = NULL;
		sprintf(a3, "%s", s2.c_str());
		sscanf(a3, "%s %s", a1, a2);
		if (strlen(a1) && strlen(a2))b = a1, bpoint = a2;
		else if (strlen(a1) && f2) bpoint = a1;
		else b = a1;
		string p, q;
		if ((flag1 == 0 && flag2 == 0) || (flag1 == 1 && flag2 == 1)) {
			if (apoint.length() < bpoint.length()) apoint.resize(bpoint.size(), 
'0');
			if (apoint.length() > bpoint.length()) bpoint.resize(apoint.size(), 
'0');
			s2 = addition(apoint, bpoint);
			for (i = s2.length() - 1; i >= 0; i--) {if (s2[i] != '0') if (i >= 0 
&& s2.length() >= i)s2.erase(s2.begin() + i, s2.end());break;}
			
			int io = 0;
			if (mark) io = 1;
			s1 = addition(a, b);
			if (io) {s1 = addition(s1, "1");if (i >= 0 && s2.length() >= 
i)s2.erase(s2.begin(), s2.begin() + 1);}
			if (s1.length() == 0) s1 = "0"; 
			if (s2.length() == 0) s2 = "0";
			if (flag1 && flag2) { 
				if(s1 != "0" && s2 == "0") cout<<"-";
				else if (s1 == "0" && s2 != "0") cout<<"-";
				else if (s1 != "0" && s2 != "0") cout<<"-";
			}
			cout<<s1<<"."<<s2<<endl;
		}
		else {
			mark = 0;
			if (apoint.length() < bpoint.length()) { 
apoint.resize(bpoint.size(), '0'); }
			if (apoint.length() > bpoint.length()) { 
bpoint.resize(apoint.size(), '0'); }
			if (a.length() < b.length()) {reverse(a.begin(), 
a.end());a.resize(b.size(), '0'); reverse(a.begin(), a.end()); }
			if (a.length() > b.length()) {reverse(b.begin(), 
b.end());b.resize(a.size(), '0'); reverse(b.begin(), b.end()); }
			p = a + apoint;
			q = b + bpoint;
			if (p < q) {s = apoint, apoint = bpoint, bpoint = s, s = a, a = b, b 
= s;}
			s2 = subtract(apoint, bpoint);
			if (mark) {b = addition(b, "1");if (i >= 0 && s2.length() >= 
i)s2.erase(s2.begin(), s2.begin() + 1);}
			for (i = s2.length() - 1; i >= 0; i--) if (s2[i] != '0') {i++;if (i 
>= 0 && s2.length() >= i)s2.erase(s2.begin() + i, s2.end());break;}
			
			s1 = subtract(a, b);
			for (i = 0; i < s1.length(); i++) if (s1[i] != '0') {if (i >= 0 && 
s1.length() >= i)s1.erase(s1.begin(), s1.begin() + i); break;}
			if (s1.length() == 0) s1 = "0"; 
			if (s2.length() == 0) s2 = "0";
			if (s1 != "0" && s2 != "0") {
				if (p < q && flag2) cout<<"-";
				if (p > q && flag1) cout<<"-";
			}
			else if (s1 != "0" && s2 == "0") {
				if (p < q && flag2) cout<<"-";
				if (p > q && flag1) cout<<"-";
			}
			else if (s2 != "0" && s1 == "0") {
				if (p < q && flag2) cout<<"-";
				if (p > q && flag1) cout<<"-";
			}
			cout<<s1<<"."<<s2<<endl;
		}
	}
	return 0;
}

admtuku
New poster
Posts: 1
Joined: Tue Feb 22, 2011 5:19 pm

10464 - Big Big Real Numbers Getting WA

Post by admtuku »

Hi,
Can anyone please give me some critical inputs and outputs???
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10464 - Big Big Real Numbers Getting WA

Post by sohel »

Have you gone through this thread?
Post Reply

Return to “Volume 104 (10400-10499)”