-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP1111.cpp
47 lines (40 loc) · 904 Bytes
/
P1111.cpp
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
41
42
43
44
45
46
47
#include <cmath>
#include <iostream>
int g_Sequence[50];
bool IsInteger(double x);
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::cin >> g_Sequence[i];
}
if (n == 1) {
a:
std::cout << 'A';
} else if (n == 2) {
if (g_Sequence[0] == g_Sequence[1]) {
std::cout << g_Sequence[0];
} else goto a;
} else {
double a = 1, b = 0;
if (g_Sequence[0] == g_Sequence[1]) {
if (g_Sequence[1] != g_Sequence[2]) {
b:
std::cout << 'B';
return 0;
}
} else {
a = (g_Sequence[2] - g_Sequence[1]) / (g_Sequence[1] - g_Sequence[0]);
b = g_Sequence[2] - a * g_Sequence[1];
if (!IsInteger(a) || !IsInteger(b)) goto b;
}
for (int i = 1; i < n; ++i) {
if (a * g_Sequence[i - 1] + b != g_Sequence[i]) goto b;
}
std::cout << a * g_Sequence[n - 1] + b;
}
}
bool IsInteger(double x) {
double intPart;
return std::modf(x, &intPart) == 0.0;
}