1. 程式人生 > >基於C#解決OJ刷題之輸入輸出問題的總結(AKOJ1064-1071A+B問題匯總)

基於C#解決OJ刷題之輸入輸出問題的總結(AKOJ1064-1071A+B問題匯總)

-s har article not edit stat sig nbsp rgs

聲明:題目部分為akoj題目,代碼為本人AC代碼。

因為本人學校的oj支持各種環境,非常正常的當中就包括了C#。然暑假在家較為空暇,本著學習C#和復習算法的態度和目的,就又開始折騰起oj了。

題目部分是最基礎的A+B系列,來看看C#的輸入輸出是怎麽一回事吧

題目地址:http://183.167.205.82:8081/JudgeOnline/problemlist?volume=1

本文由csdn-jtahstu原創。轉載請註明出處,歡迎誌同道合的朋友一起交流學習。本人QQ:1373758426 和 博客鏈接:blog.csdn.net/jtahstu

ok

A+B(1)

Time Limit:1000MS Memory Limit:65536K
Total Submit:629 Accepted:352

Description

Your task is to Calculate a + b.
Too easy?

! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20

Sample Output

6
30
Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1064
{
    class Program
    {
        static void Main(string[] args)
        {
            string sb;
            while ((sb = Console.ReadLine()) != null)
            {
                string[] s = sb.Split();
                int x = int.Parse(s[0]), y = int.Parse(s[1]);
                Console.WriteLine(x + y);
            }
        }
    }
}
C#的輸入系統非常惡心。僅僅能一行一行讀,然後分離出裏面的數據。再轉換成你想要的類型,然後才幹處理

A+B(2)

Time Limit:1000MS Memory Limit:65536K
Total Submit:459 Accepted:313

Description

Your task is to Calculate a + b.

Input

Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

2
1 5
10 20

Sample Output

6
30
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1065
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            while (n-- > 0)
            {
                string[] sb = Console.ReadLine().Split();
                int x = int.Parse(sb[0]), y = int.Parse(sb[1]);
                Console.WriteLine(x + y);
            }
        }
    }
}

和前一個幾乎相同吧,哈哈,本來這幾道題就幾乎相同

A+B(3)

Time Limit:1000MS Memory Limit:65536K
Total Submit:527 Accepted:283

Description

Your task is to Calculate the sum of some integers.

Input

Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output

For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

4 1 2 3 4
5 1 2 3 4 5
0 

Sample Output

10
15
Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1066
{
    class Program
    {
        static void Main(string[] args)
        {
            string sb;
            while ((sb = Console.ReadLine()) != null)
            {
                string[] s = sb.Split();
                int n = int.Parse(s[0]);
                if (n == 0) break;
                int sum = 0;
                for (int i = 1; i <= n; i++)
                    sum += int.Parse(s[i]);
                Console.WriteLine(sum);
            }
        }
    }
}

註意註意,這道題代碼一直RE,表示後面有一道和這就差別個輸入0結束。可是那道題AC了。這題我猜是輸入數據不是嚴格的在一行輸入的。那樣的話C#就根本沒法讀。反正我再看看,以後要是AC了,我就把這句話刪掉

A+B(4)

Time Limit:1000MS Memory Limit:65536K
Total Submit:380 Accepted:292

Description

Your task is to Calculate a + b.

Input

Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20
0 0

Sample Output

6
30
Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1067
{
    class Program
    {
        static void Main(string[] args)
        {
            string sb;
            while ((sb = Console.ReadLine()) != null)
            {
                string[] s = sb.Split();
                int x = int.Parse(s[0]), y = int.Parse(s[1]);
                if (x == 0 && y == 0) break;
                Console.WriteLine(x + y);
            }
        }
    }
}

A+B(5)

Time Limit:1000MS Memory Limit:65536K
Total Submit:393 Accepted:256

Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

2
4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15
Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1068
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            while (n-- > 0)
            {
                string[] s = Console.ReadLine().Split();
                int t = int.Parse(s[0]);
                int sum = 0, i = 1;
                while (t-- > 0)
                {
                    sum += int.Parse(s[i]);
                    i++;
                }
                Console.WriteLine(sum);
            }

        }
    }
}

A+B(6)

Time Limit:1000MS Memory Limit:65536K
Total Submit:346 Accepted:252

Description

Your task is to calculate the sum of some integers.

Input

Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output

For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15
Source

這道題AC了。可是3那道題居然RE,不就少個0結束嗎。沒啥差別啊。郁悶

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1069
{
    class Program
    {
        static void Main(string[] args)
        {
            string sb;
            while ((sb = Console.ReadLine()) != null)
            {
                string[] s = sb.Split();
                int n = int.Parse(s[0]);
                //if (n == 0) break;
                int sum = 0, i = 1;
                while (n-- > 0)
                {
                    sum += int.Parse(s[i]);
                    i++;
                }
                Console.WriteLine(sum);
            }
        }
    }
}

A+B(7)

Time Limit:1000MS Memory Limit:65536K
Total Submit:439 Accepted:258

Description

Your task is to Calculate a + b.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input

1 5
10 20

Sample Output

6

30
Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1071
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            while (n-- > 0)
            {
                string[] s = Console.ReadLine().Split();
                int t = int.Parse(s[0]);
                int sum = 0, i = 1;
                while (t-- > 0)
                {
                    sum += int.Parse(s[i]);
                    i++;
                }
                Console.WriteLine(sum);
                Console.WriteLine();
            }
        }
    }
}

OK,C#的寫法感覺怎樣?也都幾乎相同吧。我感覺是這樣,和C++、Java都殊途同歸,差別就是一些小細節吧能用在刷題上的,在家沒書,C#後面的東西沒法去看,如今還在不斷學習中,加油!



基於C#解決OJ刷題之輸入輸出問題的總結(AKOJ1064-1071A+B問題匯總)