Xiao-Dong likes to travel to various places. One day, while adventuring in a jungle, he discovered an unknown village. He found that the numbers in this village were quite special, so he decided to study them.
This village considers 7 to be a very auspicious number, so their number comparisons revolve around 7.
If there are two numbers, then between the two numbers:
- The number that can be divided by 7 is considered larger, for example, 140 is larger than 52.
- Among the numbers that can be divided by 7, the one with the larger remainder when divided by 70 is considered larger, for example, 28 is larger than 14.
- Among the numbers that cannot be divided by 7, the one with the smaller remainder when divided by 77 is considered larger, for example, 15 is larger than 16 and 68.
Now Xiao-Dong will give you some numbers. Please help Xiao-Dong find the largest number.
Sample Inputs/Outputs
Sample Inputs/Outputs | Sample Inputs/Outputs |
---|---|
EOF inputs: the numbers range between 1 and 100000, and the number 0 indicates the end of the sequence. There are at most 10 numbers, and 0 is not included in the list to be compared. | According to the village's rules for comparing numbers, output the largest number in the given sequence. If there are multiple largest numbers, please output the first one. |
7 14 28 0 | 28 |
7 77 777 0 | 7 |
52 140 0 | 140 |
15 16 68 0 | 15 |
Thought Process
The first received number can be stored in a Max variable, and then EOF can be done later. Compare one by one with the Max variable, and when comparing the size of remainders, use greater than or equal to or less than or equal to, so that the previous numbers can be set as the current maximum value.
Sample Code-ZeroJudge F707: Lucky Seven
#include <iostream>
using namespace std;
int main() {
int N, max;
cin >> max;
while (cin >> N && N != 0)
{
if (max % 7 != 0 && N % 7 == 0) max = N;
else if (max % 7 == 0 && N % 7 != 0) continue;
else if (max % 7 == 0 && N % 7 == 0)
{
if (max % 70 >= N % 70) continue;
else max = N;
}
else
{
if (max % 77 <= N % 77) continue;
else max = N;
}
}
cout << max << "\n";
}
//ZeroJudge F707
//Dr. SeanXD