刚好学校OJ支持使用C++++(C#),所以就把OJ水题当成C#的入门途径了...0v0(第一次用C#,今后遇到更简洁的方式会继续更新...)
对应HDOJ的八大输入输出格式题
C#的Console.ReadLine()输入默认为string类型,遇到一行输入可以使用Split()来分割,再使用Parse()进行转换
A+B for Input-Output Practice (I)
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem 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
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
【输入】有多组输入数据,但没有具体的告诉你有多少组,只是让你对应每组输入,应该怎样输出。
【输出】有多组输出,对应着每组输入,每组输出占一行。
代码:
using System;
using System.Collections.Generic;
namespace QwQ{
class Program{
static void Main(){
while(true) {
List<int> a =new List<string>(Console.ReadLine().Split()).ConvertAll<int>(i => int.Parse(i));
Console.WriteLine(a[0] + a[1]);
}
Console.ReadKey();
}
}
}
使用List将string转成int
C#中没有EOF,也不需要单独判断EOF,所以直接while(true)循环就可以达到循环输出的效果
A+B for Input-Output Practice (II)
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
Your task is to Calculate a + b.
Input
Your task is to Calculate a + b.
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