Comparison of Android versions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 226 Accepted Submission(s): 128
The first letter is the code name of the release family, e.g. F is Froyo. The code names are ordered alphabetically. The latest code name is K (KitKat).
The second letter is a branch code that allows Google to identify the exact code branch that the build was made from, and R is by convention the primary release branch.
The next letter and two digits are a date code. The letter counts quarters, with A being Q1 2009. Therefore, F is Q2 2010. The two digits count days within the quarter, so F85 is June 24 2010.
Finally, the last letter identifies individual versions related to the same date code, sequentially starting with A; A is actually implicit and usually omitted for brevity.
Please develop a program to compare two Android build numbers.
Each test case consists of a single line containing two build numbers, separated by a space character.
● Print "<" if the release of the first build number is lower than the second one;
● Print "=" if the release of the first build number is same as he second one;
● Print ">" if the release of the first build number is higher than the second one.
Continue to output the result of date comparison as follows:
● Print "<" if the date of the first build number is lower than the second one;
● Print "=" if the date of the first build number is same as he second one;
● Print ">" if the date of the first build number is higher than the second one.
If two builds are not in the same code branch, just compare the date code; if they are in the same code branch, compare the date code together with the individual version.
比較Android版本號,題意比較難搞清,If two builds are not in the same code branch, just compare the date code; if they are in the same code branch, compare the date code together with the individual version. 注意這句話。
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 10;
int nCase, cnt;
char A[MAXN], B[MAXN];
char judge() {
for (int i = 2; i <= 4; i++) {
if (A[i] != B[i]) {
return A[i] < B[i] ? '<' : '>';
}
}
if (A[1] == B[1]) {
char a = (A[5] == '\0' ? 'A' : A[5]);
char b = (B[5] == '\0' ? 'A' : B[5]);
return (a == b ? '=' : (a < b ? '<' : '>'));
}
return '=';
}
int main() {
scanf("%d", &nCase);
while (nCase--) {
scanf("%s%s", A, B);
char ch1 = (A[0] == B[0] ? '=' : (A[0] < B[0] ? '<' : '>'));
char ch2 = judge();
printf("Case %d: %c %c\n", ++cnt, ch1, ch2);
}
return 0;
}