In Chinese, according to the pronunciation, it can be divided into flat tone and oblique tone. Assuming we mark the flat tone as 0 and the oblique tone as 1.
A seven-character couplet consists of two sentences, each containing exactly seven characters.
There are three constraints for a seven-character couplet:
- A: 二四不同二六同: In each sentence, the second and fourth characters must have different tones, while the second and sixth characters must have the same tone.
- B: 仄起平收: The end of the first sentence must be a rising tone, while the end of the second sentence must be a level tone.
- C: 上下相對: The tone of the second, fourth, and sixth characters in both the first and second sentences must be opposite.
Given N pairs of couplets, represented by 0 and 1 to denote "ping" and "ze", please output which rules they violate. If none of the rules are violated, please output "None."
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
Input a positive integer N (1 <= N <= 30), representing the number of couplets. Following that are 2*N lines, each containing 7 numbers. The numbers are either 0 or 1. | For each couplet, output a line indicating which rules it violates. If it follows all three rules, output "None." |
1 1 1 0 0 0 1 1 1 0 0 0 1 1 0 | AC |
1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 | None |
2 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 1 1 | AB ABC |
Thought Process
You can use a vector to store the two lines of each couplet and use the index (data in the vector) to make the judgments according to the rules of the problem.
Sample Code-ZeroJudge G275: Couplets
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
for (int i = 0; i<N; i++)
{
vector<int>one;
vector<int>two;
one.push_back(-1);
two.push_back(-1);
bool A = false, B = false, C = false;
for (int j = 0; j<7; j++)
{
int tmp;
cin >> tmp;
one.push_back(tmp);
}
for (int j = 0; j<7; j++)
{
int tmp;
cin >> tmp;
two.push_back(tmp);
}
if (one[2] != one[4] && one[2] == one[6] && two[2] != two[4] && two[2] == two[6]) A = true;
if (one[7] == 1 && two[7] == 0) B = true;
if (one[2] != two[2] && one[4] != two[4] && one[6] != two[6]) C = true;
bool none = true;
if (!A)
{
none = false;
cout << "A";
}
if (!B)
{
none = false;
cout << "B";
}
if (!C)
{
none = false;
cout << "C";
}
if (none) cout << "None";
cout << "\n";
}
}
//ZeroJudge G275
//Dr. SeanXD