-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathACPC10A.cs
40 lines (34 loc) · 1.06 KB
/
ACPC10A.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Linq;
// https://www.spoj.com/problems/ACPC10A/ #sequence
// Given three successive numbers in a sequence, returns the type of sequence and the next number.
public static class ACPC10A
{
public static string Solve(int first, int second, int third)
=> IsArithmeticSequence(first, second, third)
? $"AP {third + (third - second)}"
: $"GP {third * (third / second)}";
public static bool IsArithmeticSequence(params int[] sequence)
{
int firstDifference = sequence[1] - sequence[0];
for (int i = 2; i < sequence.Length; ++i)
{
if (sequence[i] - sequence[i - 1] != firstDifference)
return false;
}
return true;
}
}
public static class Program
{
private static void Main()
{
while (true)
{
int[] line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (line.All(i => i == 0)) return;
Console.WriteLine(
ACPC10A.Solve(line[0], line[1], line[2]));
}
}
}