Praktikum_mf

Логические операции «и», «или», «не»

Dec 14th, 2021
5,222
2
Never
12
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 2 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string color1, color2, color3, color;
  7.     int floors1, floors2, floors3, floors;
  8.    
  9.     cin >> color1 >> floors1;
  10.     cin >> color2 >> floors2;
  11.     cin >> color3 >> floors3;
  12.    
  13.     cin >> color >> floors;
  14.    
  15.     bool ignore_color = color == "?"s;
  16.     bool ignore_floor = floors == -1;
  17.    
  18.     if ((ignore_color || color == color1) && (ignore_floor || floors == floors1)) {
  19.         cout << 1 << endl;
  20.     }
  21.     if ((ignore_color || color == color2) && (ignore_floor || floors == floors2)) {
  22.         cout << 2 << endl;
  23.     }
  24.     if ((ignore_color || color == color3) && (ignore_floor || floors == floors3)) {
  25.         cout << 3 << endl;
  26.     }
  27. }
Advertisement
Comments
  • qshy
    3 years
    # C++ 0.71 KB | 1 0
    1. #include <iostream>
    2. #include <string>
    3.  
    4. using namespace std;
    5.  
    6. int main() {
    7.    
    8.     string c1, c2, c3, cx;
    9.     int h1, h2, h3, hx;
    10.    
    11.     cin >> c1 >> h1 >> c2 >> h2 >> c3 >> h3 >> cx >> hx;
    12.    
    13.     if (((c1 == cx) && (h1 == hx)) || ((c1 == cx) && (hx == -1)) || ((cx == "?"s) && (h1 == hx)) || ((cx == "?"s) && (hx == -1))) {
    14.         cout << "1" << endl;
    15.     }
    16.     if (((c2 == cx) && (h2 == hx)) || ((c2 == cx) && (hx == -1)) || ((cx == "?"s) && (h2 == hx)) || ((cx == "?"s) && (hx == -1))) {
    17.         cout << "2" << endl;
    18.     }
    19.     if (((c3 == cx) && (h3 == hx)) || ((c3 == cx) && (hx == -1)) || ((cx == "?"s) && (h3 == hx)) || ((cx == "?"s) && (hx == -1))) {
    20.         cout << "3" << endl;
    21.     }
    22.    
    23. }
  • nakatoyato
    3 years
    # C++ 0.88 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string color_house_1, color_house_2, color_house_3, color_house_4;
    7.     int number_house_1, number_house_2, number_house_3, number_house_4;
    8.     cin >> color_house_1 >> number_house_1 >> color_house_2 >> number_house_2 >> color_house_3 >> number_house_3 >> color_house_4 >> number_house_4;
    9.     if (((color_house_1 == color_house_4) || (color_house_4 == "?"s)) && ((number_house_1 == number_house_4) || (number_house_4 == -1))) {
    10.         cout << 1 << endl;
    11.     }
    12.     if (((color_house_2 == color_house_4) || (color_house_4 == "?"s)) && ((number_house_2 == number_house_4) || (number_house_4 == -1))) {
    13.         cout << 2 << endl;
    14.     }
    15.     if (((color_house_3 == color_house_4) || (color_house_4 == "?"s)) && ((number_house_3 == number_house_4) || (number_house_4 == -1))) {
    16.         cout << 3 << endl;
    17.     }
    18.     return 0;
    19. }      
  • atutsasha
    3 years
    # C++ 1.17 KB | 0 0
    1. #include <iostream>
    2. #include <string>
    3. using namespace std;
    4.  
    5. int main()
    6. {
    7.     string a, b, c, d;
    8.     int a1{}, b1{}, c1{}, d1{};
    9.  
    10.     cin >> a >> a1 >> b >> b1 >> c >> c1 >> d >> d1;
    11.     /*
    12.         red 3 green 3 green 2 green -1
    13.         2 3
    14.         red 2 green 1 red 3 red 3
    15.         3
    16.         red 1 green 2 blue 3 yellow 3
    17.  
    18.         grey 5 grey 5 grey 5 grey 5
    19.         1 2 3
    20.         red 3 green 3 green 2 ? -1
    21.         1 2 3
    22.     */
    23.     if (d == "?" && d1 == -1)
    24.     {
    25.         cout << 1 << endl
    26.              << 2 << endl
    27.              << 3 << endl;
    28.     }
    29.     else if (d != "?" && d1 != -1)
    30.     {
    31.  
    32.         if (a == d && a1 == d1)
    33.         {
    34.             cout << 1 << endl;
    35.         }
    36.         if (b == d && b1 == d1)
    37.         {
    38.             cout << 2 << endl;
    39.         }
    40.         if (c == d && c1 == d1)
    41.         {
    42.             cout << 3 << endl;
    43.         }
    44.     }
    45.     else if (d == "?" || d1 == -1)
    46.     {
    47.         if (a == d || a1 == d1)
    48.         {
    49.             cout << 1 << endl;
    50.         }
    51.         if (b == d || b1 == d1)
    52.         {
    53.             cout << 2 << endl;
    54.         }
    55.         if (c == d || c1 == d1)
    56.         {
    57.             cout << 3 << endl;
    58.         }
    59.     }
    60. }
  • KartonArmadon
    3 years
    # C++ 1.51 KB | 0 0
    1. #include <iostream>
    2. #include <vector>
    3.  
    4. using namespace std;
    5.  
    6. int main() {
    7.     vector<string> colors = {};
    8.     vector<int> floors = {};
    9.     string buf_color;
    10.     int buf_floor;
    11.    
    12.     cin >> buf_color >> buf_floor;
    13.     colors.push_back(buf_color);
    14.     floors.push_back(buf_floor);
    15.     cin >> buf_color >> buf_floor;
    16.     colors.push_back(buf_color);
    17.     floors.push_back(buf_floor);
    18.     cin >> buf_color >> buf_floor;
    19.     colors.push_back(buf_color);
    20.     floors.push_back(buf_floor);
    21.    
    22.     cin >> buf_color >> buf_floor;
    23.     if (buf_floor == -1 && buf_color == "?"s) //если нет информации вообще
    24.     {
    25.         cout << 1 << endl << 2 << endl << 3 << endl;
    26.     }
    27.     else if (buf_floor == -1) //если этажность не указана
    28.     {
    29.         for (int i = 0; i < 3; i++)
    30.         {
    31.             if (buf_color == colors[i]) //сравниваем цвета
    32.                 cout << i+1 << endl;
    33.         }
    34.     }
    35.     else if (buf_color == "?"s) //если цвет не указан
    36.     {
    37.         for (int i = 0; i < 3; i++)
    38.         {
    39.             if (buf_floor == floors[i]) //сравниваем этажность
    40.                 cout << i+1 << endl;
    41.         }
    42.     }
    43.     else //если указано всё
    44.     {
    45.         for (int i = 0; i < 3; i++)
    46.         {
    47.             if (buf_floor == floors[i] && buf_color == colors[i]) //сравниваем этажность и цветность
    48.                 cout << i+1 << endl;
    49.         }
    50.     }
    51.     return 0;
    52. }
  • ASKukaev
    3 years
    # C++ 0.38 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string Color[4];
    7.     int N[4];
    8.     int i;
    9.     cin >> Color[0] >> N[0];
    10.     cin >> Color[1] >> N[1];
    11.     cin >> Color[2] >> N[2];
    12.     cin >> Color[3] >> N[3];
    13.     for (i=0; i<=2; i++) {
    14.         if (((N[i]==N[3])||(N[3]<0)) && ((Color[i]==Color[3])||(Color[3]=="?"s)))
    15.             cout << i+1 << endl;
    16.     }
    17. }
  • delix777
    3 years
    # C++ 1.74 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string color1, color2, color3;
    7.     string color_Witness{"?"s};
    8.     int floors1, floors2, floors3;
    9.     int floors_Witness{-1};
    10.     // Считайте информацию о трёх домах, которые видит перед собой Марта,
    11.     cin >> color1 >> floors1 >> color2 >> floors2 >> color3 >> floors3;
    12.    
    13.     // а также показания очевидца.
    14.     cin >> color_Witness >> floors_Witness;
    15.    
    16.     // Выведите номера тех домов (1, 2, 3) которые нужно посетить,
    17.     // по одному номеру в каждой строке
    18.    
    19.     if( color_Witness != "?"s && floors_Witness != -1 ){ // ввел и цвет и этажность
    20.         if(color1 == color_Witness && floors1 == floors_Witness) {
    21.         cout << 1 << endl;
    22.         } if(color2 == color_Witness && floors2 == floors_Witness){
    23.             cout << 2 << endl;
    24.         } if(color3 == color_Witness && floors3 == floors_Witness){
    25.             cout << 3 << endl;
    26.         }
    27.        
    28.     } else if ( color_Witness == "?"s && floors_Witness == -1 ){ // не ввел ни цвет ни этажность
    29.         cout << 1 << endl;
    30.         cout << 2 << endl;
    31.         cout << 3 << endl;
    32.        
    33.     } if( color_Witness == "?"s || floors_Witness == -1 ){ // ввёл либо цвет либо этажность
    34.         if (color1 == color_Witness || floors1 == floors_Witness){
    35.             cout << 1 << endl;
    36.         } if (color2 == color_Witness || floors2 == floors_Witness){
    37.             cout << 2 << endl;
    38.         } if (color3 == color_Witness || floors3 == floors_Witness){
    39.             cout << 3 << endl;
    40.         }
    41.     }
    42. }
  • ZateRok
    3 years
    # C++ 1.32 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.     int num_flor1, num_flor2, num_flor3, num_flor4;
    9.     cin >> house1 >> num_flor1 >> house2 >> num_flor2 >> house3 >> num_flor3 >> house4 >> num_flor4;
    10.     if (((house1 == house4) && (num_flor1 == num_flor4)) || ((house1 == house4) && (num_flor4 == -1 )) || ((house4 == "?") && (num_flor1 == num_flor4)) || ((house4 == "?") && (num_flor4 == -1))) {
    11.         cout << 1 <<endl;
    12.     } if (((house2 == house4) && (num_flor2 == num_flor4)) || ((house2 == house4) && (num_flor4 == -1 )) || ((house4 == "?") && (num_flor2 == num_flor4)) || ((house4 == "?") && (num_flor4 == -1))) {
    13.         cout << 2 <<endl;
    14.     } if (((house3 == house4) && (num_flor3 == num_flor4)) || ((house3 == house4) && (num_flor4 == -1)) || ((house4 == "?") && (num_flor3 == num_flor4)) || ((house4 == "?") && (num_flor4 == -1))) {
    15.         cout << 3 << endl;
    16.     }
    17.     return 0;
    18.    
    19.     // Считайте информацию о трёх домах, которые видит перед собой Марта,
    20.     // а также показания очевидца.
    21.     // Выведите номера тех домов (1, 2, 3) которые нужно посетить,
    22.     // по одному номеру в каждой строке
    23. }
  • wacko_dead
    3 years
    # text 1.33 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6. // Считайте информацию о трёх домах, которые видит перед собой Марта,
    7. // а также показания очевидца.
    8. // Выведите номера тех домов (1, 2, 3) которые нужно посетить,
    9. // по одному номеру в каждой строке
    10. string first_color, second_color, third_color, say_color;
    11. int first_num, second_num, third_num, say_num;
    12.  
    13. cin >> first_color >> first_num >> second_color >> second_num >> third_color >> third_num >> say_color >> say_num;
    14.  
    15. if((first_color == say_color && first_num == say_num) || (say_color == "?"s && first_num == say_num) || (first_color == say_color && say_num == -1)){
    16. cout << 1 << endl;
    17. }
    18. if((second_color == say_color && second_num == say_num) || (say_color == "?"s && second_num == say_num) || (second_color == say_color && say_num == -1)){
    19. cout << 2 << endl;
    20. }
    21. if((third_color == say_color && third_num == say_num) || (say_color == "?"s && third_num == say_num) || (third_color == say_color && say_num == -1)){
    22. cout << 3 << endl;
    23. }
    24.  
    25. if(say_color == "?"s && say_num == -1){
    26. cout << 1 << endl << 2 << endl << 3 << endl;
    27. }
    28. }
  • AlexeyLimanskiy
    3 years
    # text 1.08 KB | 0 0
    1. #include <iostream>
    2. #include <vector>
    3. #include <algorithm>
    4. #include <string>
    5. #include <utility>
    6.  
    7. using namespace std;
    8.  
    9.  
    10. int main()
    11. {
    12. string color;
    13. int number;
    14. vector<pair<string, int>> pairs;
    15.  
    16. for (size_t i = 0; i < 4; ++i)
    17. {
    18. cin >> color >> number;
    19. pairs.emplace_back(color, number);
    20. }
    21. pair<string, int> last = pairs.back();
    22. pairs.pop_back();
    23.  
    24. if (last.first == "?"s && last.second == -1)
    25. {
    26. for (int i = 1; i <= pairs.size(); ++i)
    27. {
    28. cout << i << endl;
    29. }
    30. return 0;
    31. }
    32.  
    33. if (last.first != "?"s && last.second == -1)
    34. {
    35. for (int i = 0; i < pairs.size(); ++i)
    36. {
    37. if (pairs[i].first == last.first)
    38. {
    39. cout << i + 1 << endl;
    40. }
    41. }
    42. return 0;
    43. }
    44.  
    45. if (last.first == "?"s && last.second != -1)
    46. {
    47. for (int i = 0; i < pairs.size(); ++i)
    48. {
    49. if (pairs[i].second == last.second)
    50. {
    51. cout << i + 1 << endl;
    52. }
    53. }
    54. return 0;
    55. }
    56.  
    57. if (last.first != "?"s && last.second != -1)
    58. {
    59. for (int i = 0; i < pairs.size(); ++i)
    60. {
    61. if (pairs[i] == last)
    62. {
    63. cout << i + 1 << endl;
    64. }
    65. }
    66. }
    67. }
  • zimovid
    3 years (edited)
    # C++ 1.16 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     string house_1_color, house_2_color, house_3_color, user_suggestion_house_color;
    7.     int house_1_floor, house_2_floor, house_3_floor, user_suggestion_house_floor;
    8.  
    9.     // read input
    10.     cin >> house_1_color >> house_1_floor >> house_2_color >> house_2_floor >> house_3_color >> house_3_floor >> user_suggestion_house_color >> user_suggestion_house_floor;
    11.  
    12.     // check each house against the information provided by the passerby
    13.     if ((house_1_color == user_suggestion_house_color || user_suggestion_house_color == "?") && (house_1_floor == user_suggestion_house_floor || user_suggestion_house_floor == -1)) {
    14.         cout << 1 << endl;
    15.     }
    16.     if ((house_2_color == user_suggestion_house_color || user_suggestion_house_color == "?") && (house_2_floor == user_suggestion_house_floor || user_suggestion_house_floor == -1)) {
    17.         cout << 2 << endl;
    18.     }
    19.     if ((house_3_color == user_suggestion_house_color || user_suggestion_house_color == "?") && (house_3_floor == user_suggestion_house_floor || user_suggestion_house_floor == -1)) {
    20.         cout << 3 << endl;
    21.     }
    22.  
    23.     return 0;
    24. }
    25.    
    26.    
  • nickzheleznov
    3 years
    # C++ 0.96 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     // Считайте информацию о трёх домах, которые видит перед собой Марта,
    7.     // а также показания очевидца.
    8.     // Выведите номера тех домов (1, 2, 3) которые нужно посетить,
    9.     // по одному номеру в каждой строке
    10.     string color1, color2, color3, colorx;
    11.     int floors1, floors2, floors3, floorsx;
    12.     cin >> color1 >> floors1 >> color2 >> floors2 >> color3 >> floors3 >> colorx >> floorsx;
    13.     if ((colorx == color1 || colorx == "?"s) && (floorsx == floors1 || floorsx == -1)) {
    14.         cout << 1 << endl;
    15.     }
    16.     if ((colorx == color2 || colorx == "?"s) && (floorsx == floors2 || floorsx == -1)) {
    17.         cout << 2 << endl;
    18.     }
    19.     if ((colorx == color3 || colorx == "?"s) && (floorsx == floors3 || floorsx == -1)) {
    20.         cout << 3 << endl;
    21.     }
    22. }
  • Pablos2k16
    2 years
    # C++ 1.15 KB | 0 0
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main() {
    6.     // Считайте информацию о трёх домах, которые видит перед собой Марта,
    7.     // а также показания очевидца.
    8.     // Выведите номера тех домов (1, 2, 3) которые нужно посетить,
    9.     // по одному номеру в каждой строке
    10.    
    11.     string c1, c2, c3, seen;
    12.     int h1, h2, h3, seen_cat;
    13.     cin >> c1 >> h1 >> c2 >> h2 >> c3 >> h3 >> seen >> seen_cat;
    14.    
    15.    
    16.     if ((c1 == seen && h1 == seen_cat) || (seen == "?"s && seen_cat == h1) || (seen == c1 && seen_cat == -1)) {
    17.         cout << 1 << endl;
    18.     }
    19.    
    20.     if ((c2 == seen && h2 == seen_cat) || (seen == "?"s && seen_cat == h2) || (seen == c2 && seen_cat == -1)) {
    21.         cout << 2 << endl;
    22.     }
    23.    
    24.     if ((c3 == seen && h3 == seen_cat) || (seen == "?"s && seen_cat == h3) || (seen == c3 && seen_cat == -1)) {
    25.         cout << 3 << endl;
    26.     }
    27.     else if (seen == "?"s && seen_cat == -1) {
    28.         cout << 1 << endl
    29.              << 2 << endl
    30.              << 3 << endl;
    31.     }
    32.    
    33. }
Add Comment
Please, Sign In to add comment