Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <fstream>
- using namespace std;
- class ticket {
- public:
- ticket(int);
- bool test() { return happy; }
- private:
- void search();
- int sum(int);
- int prev, current, next;
- bool happy;
- };
- int main() {
- ifstream ifs;
- ifs.open("INPUT.TXT", ifstream::in);
- if (ifs.is_open()) {
- int size;
- ifs >> size;
- if (size) {
- ofstream ofs;
- ofs.open("OUTPUT.TXT", ifstream::out);
- if (ofs.is_open()) {
- string yes("Yes\n"), no("No\n"), sum("");
- int next;
- for (int n = 0; n < size; n++) {
- ifs >> next;
- ticket tick(next);
- sum += tick.test() ? yes : no;
- }
- ofs << sum;
- ofs.close();
- }
- }
- ifs.close();
- }
- return 0;
- }
- ticket::ticket(int _ticket) : prev(_ticket - 1), current(_ticket), next(_ticket + 1), happy(false) {
- if (current > 1 && current < 999999) search();
- }
- void ticket::search() {
- int head = current / 1000, temp = head * 1000, tail = current - temp;
- if (abs(sum(head) - sum(tail)) == 1) {
- head = prev / 1000;
- tail = prev - temp;
- if (sum(head) == sum(tail)) happy = true;
- else {
- head = next / 1000;
- tail = next - temp;
- if (sum(head) == sum(tail)) happy = true;
- }
- }
- }
- int ticket::sum(int _num) {
- return _num / 100 + _num % 10 + (_num / 10) % 10;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement