Advertisement
Spocoman

Old Books

Oct 13th, 2023
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string book;
  8.     getline(cin, book);
  9.  
  10.     int bookCount, counter = 0;
  11.     cin >> bookCount;
  12.     cin.ignore();
  13.  
  14.     string command;
  15.     getline(cin, command);
  16.  
  17.     for (int i = 0; i < bookCount && command != ""; i++) {
  18.         if (command == "No More Books" || command == book) {
  19.             break;
  20.         }
  21.         counter++;
  22.         getline(cin, command);
  23.     }
  24.  
  25.     if (command == book) {
  26.         printf("You checked %i books and found it.\n", counter);
  27.     }
  28.     else {
  29.         printf("The book you search is not here!\nYou checked %i books.\n", counter);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement