C, C++/공부정리

[백준 그리디 10926] ??!

짱짱이_ 2023. 8. 7. 22:08
#include <string>
#include <cctype>  // islower
#include <iostream>

int main()
{
    std::string id[2] = {"joonas", "backjoon"};

    char input[50];

    std::cin >> input;

    std::string str(input);
    std::string exist = "??!";

    for (int i = 0; i < sizeof(id); i++)
    {
        if (std::islower(input[i]) && input == id[i])
        {
            std::cout << str + exist << std::endl;
            break;
        }
    }
    return 0;
}

 

  • 입력이 모두 소문자로 이루어져 있는지 확인하기 위해 islower()를 이용했다. cctype 라이브러리에 포함되어 있다.
  • std::string은 덧셈으로 합칠 수 있고 std::cout을 이용해 출력할 수 있다.
    printf()는 std::string를 덧셈으로 이용할 수 없다.