聲明:題目部分爲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
Sourceusing 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#後面的東西沒法去看,現在還在不斷學習中,加油!