[백준] 1. 입출력과 사칙 연산 풀이

OpenJR·2022년 7월 20일
0

[2557번] 1. Hello World

C++

#include <iostream>

int main()
{
    std::cout << "Hello World!";
    return 0;
}

Python

print("Hello World!")

[10718번] 2. We love kriii

C++

#include <iostream>

int main()
{
    std::cout << "강한친구 대한육군" << std::endl << "강한친구 대한육군";
    return 0;
}

Python

for i in range(2):
    print("강한친구 대한육군")

[10171번] 3. 고양이

C++

#include <iostream>

int main()
{
    std::cout <<
    "\\    /\\" << std::endl <<
    " )  ( ')" << std::endl <<
    "(  /  )" << std::endl <<
    " \\(__)|";
    return 0;
}

Python

print("\\    /\\")
print(" )  ( ')")
print("(  /  )")
print(" \\(__)|")

[10172번] 4. 개

C++

#include <iostream>

int main()
{
    std::cout <<
    "|\\_/|" << std::endl <<
    "|q p|   /}" << std::endl <<
    "( 0 )\"\"\"\\" << std::endl <<
    "|\"^\"`    |" << std::endl <<
    "||_/=\\\\__|";
    return 0;
}

Python

print("|\_/|")
print("|q p|   /}")
print('( 0 )"""\\')
print('''|"^"`    |''')
print("||_/=\\\\__|")

[1000번] 5. A+B

C++

#include <iostream>

int main()
{   int A, B;
    std::cin >> A >> B;
    std::cout << A + B;
    return 0;
}

Python

input_list = list(map(int, input().split()))
print(sum(input_list))

[1001번] 6. A-B

C++

#include <iostream>

int main()
{   int A, B;
    std::cin >> A >> B;
    std::cout << A - B;
    return 0;
}

Python

input_list = list(map(int, input().split()))
print(input_list[0]-input_list[-1])

[10998번] 7. AxB

C++

#include <iostream>

int main()
{   int A, B;
    std::cin >> A >> B;
    std::cout << A * B;
    return 0;
}

Python

input_list = list(map(int, input().split()))
print(input_list[0]*input_list[-1])

[1008번] 8. A/B

C++

#include <iostream>

int main()
{   int A, B;
    std::cin >> A >> B;
    std::cout << A / B;
    return 0;
}

Python

input_list = list(map(float, input().split()))
print(input_list[0]/input_list[-1])

[10869번] 9. 사칙연산

C++

#include <iostream>

int main()
{   int A, B;
    std::cin >> A >> B;
    std::cout << A + B << std::endl;
    std::cout << A - B << std::endl;
    std::cout << A * B << std::endl;
    std::cout << A / B << std::endl;
    std::cout << A % B << std::endl;
    return 0;
}

Python

input_list = list(map(int, input().split()))
print(input_list[0]+input_list[-1])
print(input_list[0]-input_list[-1])
print(input_list[0]*input_list[-1])
print(input_list[0]//input_list[-1])
print(input_list[0]%input_list[-1])

[10926번] 10. ??!

C++

#include <iostream>
#include <string>

int main()
{
    std::string str;
    std::cin >> str;
    std::cout << str << "??!";
    return 0;
}

Python

input_str = input()
print(input_str+"??!")

[18108번] 11. 1998년생인 내가 태국에서는 2541년생?!

C++

#include <iostream>

int main()
{
    int year;
    std::cin >> year;
    std::cout << year - 543;
    return 0;
}

Python

input_int = int(input())
print(input_int-543)

[10430번] 12. 나머지

C++

#include <iostream>

int main()
{
    int A, B, C;
    std::cin >> A >> B >> C;
    std::cout <<
    (A+B)%C << std::endl <<
    ((A%C) + (B%C))%C << std::endl <<
    (A*B)%C << std::endl <<
    ((A%C) * (B%C))%C;
    return 0;
}

Python

A, B, C = list(map(int, input().split()))
print((A+B)%C)
print(((A%C) + (B%C))%C)
print((A*B)%C)
print(((A%C) * (B%C))%C)

[2588번] 13. 곱셈

C++

#include <iostream>
#include <string>

int main()
{
    std::string A, B;
    std::cin >> A >> B;
    std::cout << stoi(A) * stoi(B.substr(2,1)) << std::endl <<
                 stoi(A) * stoi(B.substr(1,1)) << std::endl <<
                 stoi(A) * stoi(B.substr(0,1)) << std::endl <<
                 stoi(A) * stoi(B) << std::endl;
    
    return 0;
}

Python

A, B = input(), input()
print(int(A)*int(B[-1]))
print(int(A)*int(B[-2]))
print(int(A)*int(B[-3]))
print(int(A)*int(B))

[25083번] 14. 새싹

C++

#include <iostream>

int main()
{
    std:: cout <<
    "         ,r\'\"7" << std::endl <<
    "r`-_   ,\'  ,/" << std::endl <<
    " \\. \". L_r\'" << std::endl <<
    "   `~\\/" << std::endl <<
    "      |" << std::endl <<
    "      |";
}

Python

str ='''         ,r'"7
r`-_   ,'  ,/
 \. ". L_r'
   `~\/
      |
      |
'''
print(str)
profile
Jacob

0개의 댓글