# You can use the online ACM library in C # language.

Source: Internet
Author: User

You can use the online ACM library in C # language.
The online Q & A library of Russian uural University is an online ACM library that can use C # language. If you are interested, try it.

Problem 1000. A + B Problem is an entry, that is, simply calculate the sum of integers A and B. The answer is as follows:

1 using System;
2
3 //Http://acm.timus.ru/problem.aspx? Space = 1& Num = 1000
4 class Acm1000
5 {
6 static void Main ()
7 {
8 string [] ss = Console. ReadLine (). Split ();
9 Console. WriteLine (long. Parse (ss ) + long. Parse (ss );
10}
11}
12
Problem 1001. Reverse root is also very simple, that is, to give a group of integers, and then output its square root in Reverse order. The answer is as follows:

1 using System;
3 using System. Globalization;
4 using System. Text. RegularExpressions;
5
6 //Http://acm.timus.ru/problem.aspx? Space = 1& Num = 1001
7 class Acm1001
8 {
9 static void Main ()
10 {
12 string [] nums = Regex. Split (Console. In. ReadToEnd (). Trim (), @ s + );
13 for (int I = nums. Length-1; I> = 0; I --)
14 Console. WriteLine ({0: F4}, Math. Sqrt (ulong. Parse (nums [I]);
15}
16}
17
Note that line 1 of the program cannot be omitted, otherwise it will fail. I still don't know why. (The reason has been found. Please refer to the comments on the second floor ).

Problem 1005. Stone pile requires that several stones be divided into two heaps to minimize the weight difference. The answer is as follows:

1 using System;
2 using System. IO;
3 using System. Text. RegularExpressions;
4
5 //Http://acm.timus.ru/problem.aspx? Space = 1& Num = 1005
6 class Acm1005
7 {
8 static void Main ()
9 {
10 new Acm1005 (). Run (Console. In, Console. Out );
11}
12
14 {
15 writer. WriteLine (GetResult (GetWeigths (reader )));
16}
17
19 {
20 string [] ss = Regex. Split (reader. ReadToEnd (). Trim (), @ s + );
21 int [] weigths = new int [int. Parse (ss )];
22 for (int I = 0; I <weigths. Length; I ++) weigths [I] = int. Parse (ss [I + 1]);
23 return weigths;
24}
25
26 int GetResult (int [] weigths)
27 {
28 int n = weigths. Length-1;
29 int result = int. MaxValue;
30 int [] piles = new int ;
31 for (int I = (1 <n)-1; I> = 0; I --)
32 {
33 piles  = weigths [n];
34 piles  = 0;
35 for (int j = n-1; j> = 0; j --) piles [(I> j) & 1) = 0 )? 1: 0] + = weigths [j];
36 int v = Math. Abs (piles -piles );
37 if (result> v) result = v;
38}
39 return result;
40}
41}
42

Problem 1068. Sum is also very simple, that is, the Sum of 1 to N. The answer is as follows:

1 using System;
2
3 //Http://acm.timus.ru/problem.aspx? Space = 1& Num = 1068
4 class Acm1068
5 {
6 static void Main ()
7 {
8 Console. WriteLine (Sum (int. Parse (Console. ReadLine ())));
9}
10
11 static long Sum (long n)
12 {
13 if (n> 0) return n * (n + 1)/2;
14 if (n <0) return 1 + n * (1-n)/2;
15 return 1;
16}
17}
18
Problem 1070. A local time is required to calculate the time difference between the two places based on the time (expressed by the local time) of the round-trip flight between the two places. The answer is as follows:

1 using System;
2 using System. IO;
3
4 //Http://acm.timus.ru/problem.aspx? Space = 1& Num = 1070
5 class Acm1070
6 {
7 static void Main ()
8 {
9 new Acm1070 (). Run (Console. In, Console. Out );
10}
11
13 {
14 double diff1 = GetDuration (reader );
15 double diff2 = GetDuration (reader );
16 writer. WriteLine (Math. Abs (int) Math. Round (diff1-diff2)/2 )));
17}
18
20 {
22 double diff = (GetTime (ss )-GetTime (ss ). TotalHours;
23 if (diff> 6) diff-= 24;
24 if (diff <-6) diff + = 24;
25 return diff;
26}
27
28 DateTime GetTime (string s)
29 {
30 string [] ss = s. Split ('.');
31 return new DateTime (1, 1, 1, int. Parse (ss ), int. Parse (ss ), 0 );
32}
33}
34
Other questions may not be so easy. :)

According to comments from Friends of CppGohan on the eighth floor, Sphere Onlile Judge (SPOJ) is also an online ACM library that supports C # languages.

1. Life, the Universe, and Everything is an entry, that is, copying the standard input as is to the standard output in one row until a row is "42". the answer is as follows:

1 using System;
2 using System. IO;
3
4 // Http://www.spoj.pl/problems/TEST/
5 class S1
6 {
7 static void Main ()
8 {
9 new S1 (). Run (Console. In, Console. Out );
10}
11
13 {
14 (;;)
15 {
17 if (s = null) break;
18 if (s = 42) break;
19 writer. WriteLine (s );
20}
21}
22}
23

2. Prime Generator requires that multiple groups of Prime numbers in the specified range be generated. The answer is as follows:

1 using System;
2 using System. IO;
3
4 // Http://www.spoj.pl/problems/PRIME1/
5 class S2
6 {
7 struct Range
8 {
9 public int Min;
10 public int Max;
11}
12
13 static void Main ()
14 {
15 new S2 (). Run (Console. In, Console. Out );
16}
17
19 {
20 int theMax;
21 Range [] ranges = GetRanges (reader, out theMax );
22 int min = 3;
23 int max = (int) Math. Sqrt (theMax) + 1;
24 if (max & 1) = 0) max --;
25 int [] primes = GetPrimes (GetSieve (min, max), min, max );
26 foreach (Range range in ranges)
27 {
28 min = range. Min;
29 max = range. Max;
30 if (min = 1) min = 3;
31 if (min & 1) = 0) min ++;
32 if (max & 1) = 0) max --;
33 OutPrimes (writer, GetSieve (primes, min, max), min, max, range. Min, range. Max );
34}
35}
36
38 {
39 max = 0;
40 Range [] ranges = new Range [int. Parse (reader. ReadLine ()];
41 for (int I = 0; I <ranges. Length; I ++)
42 {
44 ranges [I]. Min = int. Parse (ss );
45 ranges [I]. Max = int. Parse (ss );
46 if (max <ranges [I]. Max) max = ranges [I]. Max;
47}
48 return ranges;
49}
50
51 bool [] GetSieve (int min, int max)
52 {
53 bool [] sieve = new bool [(max-min)> 1) + 1];
54 int sqrt = (int) Math. Sqrt (max) + 1;
55 for (int n = min; n <= sqrt; n + = 2) if (! Sieve [(n-min)> 1]) SetSieve (sieve, n, min, max );
56 return sieve;
57}
58
59 bool [] GetSieve (int [] primes, int min, int max)
60 {
61 bool [] sieve = new bool [(max-min)> 1) + 1];
62 int sqrt = (int) Math. Sqrt (max) + 1;
63 for (int I = 0; primes [I] <= sqrt; I ++) SetSieve (sieve, primes [I], min, max );
64 return sieve;
65}
66
67 void SetSieve (bool [] sieve, int v, int min, int max)
68 {
69 int step = v <1;
70 for (int n = GetStart (v, min); n <= max; n + = step) sieve [(n-min)> 1] = true;
71}
72
73 int GetStart (int v, int min)
74 {
75 int v2 = v * v;
76 if (v2> = min) return v2;
77 int x = min/v;
78 if (x & 1) = 0) x ++;
79 v2 = x * v;
80 if (v2 <min) v2 + = v * 2;
81 return v2;
82}
83
84 int [] GetPrimes (bool [] sieve, int min, int max)
85 {
86 int [] primes = new int ;
87 int I = 0;
88 for (int n = min; n <= max; n + = 2) if (! Sieve [(n-min)> 1]) primes [I ++] = n;
89 primes [I] = int. MaxValue;
90 return primes;
91}
92
93 void OutPrimes (TextWriter writer, bool [] sieve, int min, int max, int min0, int max0)
94 {
95 if (min0 <= 2 & max0> = 2) writer. WriteLine (2 );
96 for (int n = min; n <= max; n + = 2) if (! Sieve [(n-min)> 1]) writer. WriteLine (n );
97 writer. WriteLine ();
98}
99}
100

Sphere Onlile Judge (SPOJ) should use the Linux operating system. Currently, the C # compiler is mcs 1.0.1 (a little old, the latest version is 1.9.1), and the C/C ++ compiler is gcc 4.0.0-8 (a little old, the latest version is 4.3.1 ).

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## 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.