Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string book, input;
- getline(cin, book);
- getline(cin, input);
- int counter = 0;
- while (input != "No More Books" && input != book) {
- counter++;
- getline(cin, input);
- }
- if (input == "No More Books") {
- cout << "The book you search is not here!\nYou checked " << counter << " books.";
- }
- else {
- cout << "You checked " << counter << " books and found it.";
- }
- return 0;
- }
- Решение с for тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string book, input;
- getline(cin, book);
- for (int i = 0; i < 2147483647; i++) { // INT_MAX = 2147483647
- getline(cin, input);
- if (input == "No More Books" || input == book) {
- input == book ?
- cout << "You checked " << i << " books and found it." :
- cout << "The book you search is not here!\nYou checked " << i << " books.";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement