Four Lake Problems (enumeration method)

Source: Internet
Author: User

A: Dongting Lake is the largest, the Hongze lake is the smallest, the third.
B: Hongze Lake is the largest, Dongting lake is the smallest, Poyang Lake second, Taihu third.
C: The Hongze lake is the smallest and the third.
Ding: Poyang Lake is the largest, Taihu Lake, the second, Dongting Lake third.
Given the size of each lake, it is known that each person is only right, and if you let the computer use this information to judge the university rankings of four lakes, you also need to have logical reasoning skills.

The code is as follows:

#include <iostream>using namespace Std;int main () {int dt,hz,py,th;    BOOL Flag=false; for (dt=1; dt<=4&&!flag; ++DT) {for (hz=1; hz<=4&&!flag;            ++hz) {if (dt==hz) continue; else for (Py=1; py<=4&&!flag; ++py) {if (py==dt| |                    PY==HZ) continue;                        else {th=10-dt-py-hz; if ((dt==1) + (hz==4) + (py==3)) ==1&& ((hz==1) + (dt==4) + (py==2) + (th==3)) ==1 && (( hz==4) + (dt==3)) ==1 && ((py==1) + (th==4) + (hz==2) + (dt==3)) ==1) {Cou t<< "Dongting Lake" <<DT<< "name \ n Hongze Lake," <<HZ<< "name \ Na ' an" <<PY<< "Lake Taihu First" <<TH<                            < "name \ n";                        Flag=true; }                    }                }        }    }    return 0;} 

Operation Result:



Four Lake Problems (enumeration method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.