結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー myantamyanta
提出日時 2017-06-28 02:10:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,356 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 26,880 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 22:41:00
合計ジャッジ時間 1,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>


using ll=long long;


class mbn
{
	ll a, b;
	int s;
public:
	mbn()
	{
		a=b=0LL;
		s=0;
	}
	void set(const char *p)
	{
		s=0;
		a=b=0;
		if(*p=='-')
		{
			s=1;
			p++;
		}
		for(;*p;p++)
		{
			if(*p=='.')
			{
				p++;
				break;
			}
			a=a*10+(*p-'0');
		}
		for(int i=0;i<10;i++)
		{
			if(*p=='\0')
			{
				b*=10;
			}
			else
			{
				b=b*10+(*p-'0');
				p++;
			}
		}
	}
	const mbn operator+(const mbn rhs)
	{
		mbn r;
		if(s==rhs.s)
		{
			int c=0;
			r.s=s;
			r.b=b+rhs.b;
			if(r.b>=10000000000LL)
			{
				r.b-=10000000000LL;
				c=1;
			}
			r.a=a+rhs.a+c;
		}
		else
		{
			if(abs_cmp(rhs)>=0)
			{
				int c=0;
				r.s=s;
				r.b=b-rhs.b;
				if(r.b<0)
				{
					r.b+=10000000000LL;
					c=1;
				}
				r.a=a-rhs.a-c;
			}
			else
			{
				int c=0;
				r.s=rhs.s;
				r.b=rhs.b-b;
				if(r.b<0)
				{
					r.b+=10000000000LL;
					c=1;
				}
				r.a=rhs.a-a-c;
			}
		}
		return r;
	}
	int abs_cmp(const mbn rhs)
	{
		if(a>rhs.a) return 1;
		if(a<rhs.a) return -1;
		if(b>rhs.b) return 1;
		if(b<rhs.b) return -1;
		return 0;
	}
	void print(void)
	{
		printf("%s%lld.%010lld\n", s?"-":"", a, b);
	}
};


int main(void)
{
	int n;

	while(scanf("%d\n", &n)==1)
	{
		mbn ans;
		for(int i=0;i<n;i++)
		{
			char buf[24+2]={0};
			mbn x;

			scanf("%24[-0-9.]\n", buf);
			x.set(buf);
			ans=ans+x;
		}
		ans.print();
	}
}
0