結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー mbanmban
提出日時 2017-01-07 00:46:42
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,597 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 107,708 KB
実行使用メモリ 24,808 KB
最終ジャッジ日時 2023-08-22 15:38:04
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 60 ms
20,732 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 60 ms
20,800 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 60 ms
24,808 KB
testcase_14 AC 60 ms
22,712 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 60 ms
22,764 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 59 ms
18,628 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 60 ms
20,780 KB
testcase_25 AC 60 ms
22,764 KB
testcase_26 AC 60 ms
20,632 KB
testcase_27 AC 59 ms
20,684 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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 Plus=new Number("0.0"), Minus=new Number("-0.0");
        for(int i = 0; i < N; i++)
        {
            Number read = new Number(Console.ReadLine());
           // Console.WriteLine(read.toString());
            if (read.Positive)
            {
                Plus += read;
            }
            else
            {
                Minus += read;
            }
        }
        Console.WriteLine((Plus + Minus).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;
                }
            }
            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;
        }
        return new Number("0");
    }
    
}
0