結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー mbanmban
提出日時 2017-01-07 00:07:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,630 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 105,776 KB
実行使用メモリ 24,848 KB
最終ジャッジ日時 2023-08-22 15:36:11
合計ジャッジ時間 4,955 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
18,640 KB
testcase_01 AC 57 ms
20,764 KB
testcase_02 AC 57 ms
20,704 KB
testcase_03 WA -
testcase_04 AC 58 ms
22,780 KB
testcase_05 AC 58 ms
22,760 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 57 ms
22,684 KB
testcase_27 AC 58 ms
20,760 KB
testcase_28 AC 59 ms
22,756 KB
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;
            ca.Positive ^= true;
            return ca;
        }
        return new Number("0");
    }
    
}
0