当前位置: 代码迷 >> C# >> 基于C#解决OJ刷题之输入输出有关问题的总结(AKOJ1064-1071A+B有关问题汇总)
  详细解决方案

基于C#解决OJ刷题之输入输出有关问题的总结(AKOJ1064-1071A+B有关问题汇总)

热度:15   发布时间:2016-05-05 03:08:40.0
基于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#后面的东西没法去看,现在还在不断学习中,加油!

版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案