結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2017-01-07 01:28:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,334 bytes |
| コンパイル時間 | 838 ms |
| コンパイル使用メモリ | 116,464 KB |
| 実行使用メモリ | 27,852 KB |
| 最終ジャッジ日時 | 2024-12-17 15:14:52 |
| 合計ジャッジ時間 | 2,343 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
class Magatro
{
static int N = int.Parse(Console.ReadLine());
static void Main()
{
Number ans = new Number("0");
for(int i = 0; i < N; i++)
{
ans += new Number(Console.ReadLine());
}
Console.WriteLine(ans.toString());
}
}
struct Number
{
public bool Positive;
public long Integer, Fraction;
public Number(string s)
{
Number r = new Number();
r.Positive = s[0] != '-';
if (!r.Positive) s = s.Remove(0, 1);
string[] q = s.Split('.');
r.Integer = long.Parse(q[0]);
if (q.Length == 1)
{
r.Fraction = 0;
}
else
{
r.Fraction = long.Parse(q[1].PadRight(10, '0'));
}
Positive = r.Positive ;
Integer = r.Integer;
Fraction = r.Fraction;
}
public string toString()
{
string ret = "";
if (!Positive)
{
ret = "-";
}
ret += Integer.ToString();
ret += ".";
ret += Fraction.ToString().PadRight(10, '0');
return ret;
}
public static Number operator +(Number a,Number b)
{
if (a.Positive && b.Positive)
{
Number r = new Number();
r.Positive = true;
r.Integer = a.Integer + b.Integer;
r.Fraction = a.Fraction + b.Fraction;
r.Integer += r.Fraction / 10000000000;
r.Fraction %= 10000000000;
return r;
}
else if (!a.Positive && !b.Positive)
{
Number ca = a, cb = b;
ca.Positive = true;
cb.Positive = true;
Number r = ca + cb;
r.Positive = false;
return r;
}
else if(!a.Positive&&b.Positive)
{
Number ca = new Number();
ca.Integer = -a.Integer + b.Integer;
ca.Fraction = -a.Fraction + b.Fraction;
ca.Integer += ca.Fraction / 10000000000;
ca.Fraction %= 10000000000;
if (ca.Integer > 0)
{
ca.Positive = true;
if (ca.Fraction < 0)
{
ca.Integer--;
ca.Fraction += 10000000000;
}
return ca;
}
else if (ca.Integer < 0)
{
ca.Positive = false;
if (ca.Fraction > 0)
{
ca.Integer++;
ca.Fraction -= 10000000000;
ca.Fraction *= -1;
}
ca.Integer *= -1;
return ca;
}
else
{
if (ca.Fraction >= 0)
{
ca.Positive = true;
}
else
{
ca.Positive = false;
ca.Fraction *= -1;
}
return ca;
}
}
else
{
Number ca = new Number();
ca = b+a;
return ca;
}
}
}
mban