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

來源:互聯網
上載者:User

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

     聲明:題目部分為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 510 20

Sample Output

630
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

21 510 20

Sample Output

630
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 45 1 2 3 4 50 

Sample Output

1015
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 510 200 0

Sample Output

630
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

24 1 2 3 45 1 2 3 4 5

Sample Output

1015
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 45 1 2 3 4 5

Sample Output

1015
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 510 20

Sample Output

630
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#後面的東西沒法去看,現在還在不斷學習中,加油!

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.