基于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 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#后面的东西没法去看,如今还在不断学习中,加油!



转载于:https://www.cnblogs.com/ljbguanli/p/7217317.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值