Praktikum_mf

Логические операции: сравнение / Задание 1

Dec 14th, 2021
3,288
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string house_color_1, house_color_2, house_color_3, target_house_color;
  7.     cin >> house_color_1 >> house_color_2 >> house_color_3 >> target_house_color;
  8.    
  9.     int house_number = 0;
  10.     if (target_house_color == house_color_1) {
  11.         house_number = 1;
  12.     } else if (target_house_color == house_color_2) {
  13.         house_number = 2;
  14.     } else if (target_house_color == house_color_3) {
  15.         house_number = 3;
  16.     }
  17.    
  18.     if (house_number != 0) {
  19.         cout << "Enter the house "s << house_number << endl;
  20.     } else {
  21.         cout << "Seek somewhere else"s << endl;
  22.     }
  23. }
Advertisement
Comments
  • IIaJIpaTiN
    3 years
    # C++ 0.49 KB | 1 0
    1. #include <iostream>
    2. #include <string>
    3.  
    4. using namespace std;
    5.  
    6. int main() {
    7.     string firstColor, secondColor, thirdColor, needColor;
    8.     cin >> firstColor >> secondColor >> thirdColor >> needColor;
    9.     int houseNum = (firstColor == needColor) + (secondColor == needColor) * 2 + (thirdColor == needColor) * 3;
    10.     if (houseNum != 0) {
    11.         cout << "Enter the house "s + to_string(houseNum) << endl;
    12.     } else {
    13.         cout << "Seek somewhere else"s << endl;
    14.     }
    15.     return 0;
    16. }
  • MaratSR
    3 years
    # C++ 0.44 KB | 0 0
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. int main() {
    5.     string h1, h2, h3, h_cat;
    6.     cin >> h1 >> h2 >> h3 >> h_cat;
    7.     if (h1 == h_cat) {
    8.         cout << "Enter the house 1";
    9.         return 0;
    10.     }
    11.     if (h2 == h_cat) {
    12.         cout << "Enter the house 2";
    13.         return 0;
    14.        }
    15.     if (h3 == h_cat) {
    16.         cout << "Enter the house 3";
    17.         return 0;
    18.     }
    19.     cout << "Seek somewhere else"s;
    20.     return 0;
    21. }
  • Viewfim
    3 years (edited)
    # C++ 0.46 KB | 1 0
    1. using namespace std;
    2. int main() {  
    3. string dc1, dc2, dc3, pc;
    4.     cout << "Enter the house X"s << endl;
    5.     cin >> dc1 >> dc2 >> dc3 >> pc;
    6.     if (pc == dc1 || pc == dc2 || pc == dc3) {
    7.         if (pc == dc1) { cout << "Enter the house 1"s << endl; }
    8.         if (pc == dc2) { cout << "Enter the house 2"s << endl; }
    9.         if (pc == dc3) { cout << "Enter the house 3"s << endl; }
    10.     }
    11.     else {
    12.         cout << "Seek somewhere else"s << endl;
    13.     }
    14. }
  • ASKukaev
    3 years
    # text 0.37 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6. bool Found=0;
    7. int i;
    8. string s[4];
    9. cin >>s[0]>>s[1]>>s[2]>>s[3];
    10. for (i=0; i<=2; i++)
    11. if (s[i] == s[3]){
    12. cout << "Enter the house "s << i+1 << endl;
    13. Found = 1;
    14. break;
    15. }
    16. if (!Found)
    17. cout << "Seek somewhere else"s << endl;
    18. }
  • delix777
    3 years
    # C++ 0.76 KB | 1 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string color1, color2, color3, color;
    7.     // Считайте цвета трёх домов и цвет дома, где видели Пушистика
    8.     cin >> color1 >> color2 >> color3 >> color;
    9.     // Выведите Enter the house X, если дом нужного цвета имеет номер X
    10.     if(color1 == color){
    11.         cout << "Enter the house 1"s << endl;
    12.     } else if(color2 == color){
    13.         cout << "Enter the house 2"s << endl;
    14.     } else if(color3 == color){
    15.         cout << "Enter the house 3"s << endl;
    16.     } // Выведите Seek somewhere else, если дома нужного цвета нет
    17.     else {
    18.         cout << "Seek somewhere else"s << endl;
    19.     }
    20. }
  • ZateRok
    3 years
    # C++ 0.84 KB | 0 0
    1. #include <iostream>
    2. #include <string>
    3.  
    4. using namespace std;
    5.  
    6. int main() {
    7.     string house1, house2, house3, house4;
    8.     cin >> house1 >> house2 >> house3 >> house4;
    9.     if (house1 == house4) {
    10.         cout << "Enter the house 1"s << endl;
    11.     } if (house2 == house4) {
    12.         cout << "Enter the house 2"s << endl;
    13.     } if (house3 == house4) {
    14.         cout << "Enter the house 3"s << endl;
    15.     } if ((house1 != house4) && (house2 != house4) && (house3 != house4)) {
    16.         cout << "Seek somewhere else"s << endl;
    17.     }
    18.     return 0;
    19.          // трёх домов и цвет дома, где видели Пушистика
    20.     // Выведите Enter the house X, если дом нужного цвета имеет номер X
    21.     // Выведите Seek somewhere else, если дома нужного цвета нет
    22. }
  • cattraydancer
    3 years (edited)
    Comment was deleted
  • cattraydancer
    3 years
    # C++ 0.40 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string h1, h2, h3, h4;
    7.     cin >> h1 >> h2 >> h3 >> h4;
    8.     if (h4 == h1) {
    9.         cout << "Enter the house 1"s << endl;
    10.     } else if (h4 == h2) {
    11.         cout << "Enter the house 2"s << endl;
    12.     } else if (h4 == h3) {
    13.         cout << "Enter the house 3"s << endl;
    14.     } else {
    15.         cout << "Seek somewhere else"s << endl;
    16.     }
    17. }
  • nickzheleznov
    3 years
    # C++ 0.94 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     // Считайте три целых числа: X и Y и их сумму
    7.     // Если сумма указана неверно, выведите сообщение: "Error. The sum of X and Y is Z"
    8.     // Вместо символов X, Y и Z выведите числа X и Y, а также правильное значение суммы
    9.     int x, y, z;
    10.     cin >> x >> y >> z;
    11.     bool correct_range = ((x >= -1000000 || x <= 1000000) && (y >= -1000000 || y <= 1000000));
    12.     if (correct_range) {
    13.         if (x + y != z) {
    14.             cout << "Error. The sum of " << x << " and " << y << " is " << x + y << endl;
    15.         }
    16.     }
    17. }
    18.  
    19. //Со стандартного входа программе поступают три целых числа в диапазоне от -1'000'000 до +1'000'000 - из условия, поэтому добавил проверку..
Add Comment
Please, Sign In to add comment