โ 2557 Hello World โ
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
}
โ 1000 A + B โ / โ 1001 A - B โ / โ 10998 A x B โ
#include <iostream>
using namespace std;
int main()
{
int A, B;
cin >> A;
cin >> B;
cout << A * B; // A - B, A + B
return 0;
}
โ 1008 A / B โ
#include <iostream>
using namespace std;
int main()
{
double A, B;
cin >> A >> B;
cout.precision(12);
cout << fixed;
cout << A / B;
return 0;
}
๐ค cout.precision(12)์ผ๋ก ์ค์ ์ ์ฒด๋ฅผ 12์๋ฆฌ๋ก ํํํ๊ฒ ๋ค๋ ๋ป.
๐ค fixed ์จ์ 12์๋ฆฌ๋ก ๊ณ ์ ํ ์ซ์๋ก ์ฐ์ฐ. fixed ์ดํ๋ 12์๋ฆฌ๋ก ๊ณ ์ ํ ์ซ์๋ก ์ฐ์ฐ์ ์งํ.
โ 10869 ์ฌ์น์ฐ์ฐ โ
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << "\n";
cout << a - b << "\n";
cout << a * b << "\n";
cout << a / b << "\n";
cout << a % b << "\n";
return 0;
}
๐ค ๋ชซ์ / ๊ธฐํธ, ๋๋จธ์ง๋ % ๊ธฐํธ ์ฌ์ฉ. ๊ทธ๋ฆฌ๊ณ endl ๋์ "\n"์ ์ฌ์ฉํด ๊ทธ ๋ค์ ์ค ์ถ๋ ฅ ์งํ
โ 10926 ??! โ
//10926
#include <iostream>
#include <string>
using namespace std;
int main()
{
string id;
cin >> id;
id += "??!";
cout << id;
return 0;
}
๐ค ๋ฌธ์์ด์ <string> library๋ฅผ ๊ฐ์ ธ์ค๊ณ , string ๋ณ์ id๋ฅผ ๋ง๋ค์ด์ ์ ๋ ฅ ํ, ??! ๋ถ์ฌ์ ์ถ๋ ฅ
โ 18108 1998๋ ์์ธ ๋ด๊ฐ ํ๊ตญ์์๋ 2541๋ ์?! โ
//18108
#include <iostream>
#include <string>
using namespace std;
int main()
{
int year;
cin >> year;
cout << year - 543 << '\n';
return 0;
}
โ 10430 ๋๋จธ์ง โ
//10430
#include <iostream>
#include <string>
using namespace std;
int main()
{
int A, B, C;
cin >> A >> B >> C;
cout << (A+B)%C << "\n" << ((A%C) + (B%C))%C << "\n" << (A*B)%C << "\n" << ((A%C)*(B%C))%C << "\n";
return 0;
}
โ 2588 ๊ณฑ์ โ
//2588
#include <iostream>
#include <string>
using namespace std;
int main()
{
int A;
string B;
cin >> A >> B ;
cout << A * (B[2] - '0') << "\n";
cout << A * (B[1] - '0') << "\n";
cout << A * (B[0] - '0') << "\n";
cout << A * stoi(B) << "\n";
return 0;
}
๐ค (ํ ๊ฐ์ ๋ฌธ์) B[2] - '0'์ผ๋ก ์ฃผ์ด์ง ์ซ์ ๋ฌธ์์ '0'์ ๋นผ์ ์ค์ ์ซ์๋ก ๋ณํ / (๋ฌธ์์ด) ์ง์ stoi() ํจ์๋ฅผ ํ์ฉ
โ 11382 ๊ผฌ๋ง ์ ๋ฏผ โ
//11382
#include <iostream>
#include <string>
using namespace std;
int main()
{
long long A, B, C;
cin >> A >> B >> C;
cout << A + B + C << "\n";
return 0;
}
๐ค ๋งค์ฐ ํฐ ์ซ์๋ int๊ฐ ์๋๋ผ long long ํ์ ์ผ๋ก ๋ฐ๊พธ์ด์ ์งํ
โ 10171 ๊ณ ์์ด โ
//10171
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
cout << "\\ /\\\n";
cout << " ) ( ')\n";
cout << "( / )\n";
cout << " \\(__)|\n";
return 0;
}
๐ค ์ญ์ฌ๋์(\)๋ฅผ ์ถ๋ ฅํ๊ณ ์ถ๋ค๋ฉด ์์ ์ญ์ฌ๋์๋ฅผ ํ ๋ฒ ๋ ๋ถ์ด๋ฉด ๋๋ค.
โ 10172 ๊ฐ โ
//10172
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
cout << "|\\_/|\n";
cout << "|q p| /}\n";
cout << "( 0 )\"\"\"\\\n";
cout << "|\"^\"` |\n";
cout << "||_/=\\\\__|\n";
return 0;
}
๐ค ์ญ์ฌ๋์ + ํฐ๋ฐ์ดํ + ์์๋ฐ์ดํ ๋ชจ๋ ์ถ๋ ฅํ๊ณ ์ถ๋ค๋ฉด ์์ ์ญ์ฌ๋์๋ฅผ ํ ๋ฒ ๋ ๋ถ์ด๋ฉด ๋๋ค.
โ 11021 A + B - 7 โ
//11021
#include <iostream>
#include <string>
using namespace std;
int main(){
int T;
cin >> T;
for(int i = 0; i < T; i++) {
int A, B;
cin >> A >> B;
cout << "Case #" << i+1 << ": " << A + B << '\n';
}
}
โ 11022 A + B - 8 โ
//11022
#include <iostream>
#include <string>
using namespace std;
int main(){
int T;
cin >> T;
for(int i = 0; i < T; i++) {
int A, B;
cin >> A >> B;
cout << "Case #" << i+1 << ": " << A << " + " << B << " = " << A + B << '\n';
}
}
โ 15552 ๋น ๋ฅธ A+B โ
#include <iostream>
#include <string>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
for(int x = 0; x < N; x++){
int A, B;
cin >> A >> B;
cout << A + B << '\n';
}
}
๐ค c++์์ ๋น ๋ฅด๊ฒ ์ ๋ ฅ๋ฐ์ผ๋ ค๋ฉด cin.tie(NULL) / cout.tie(NULL) / ios_base::sync_with_stdio(false)๋ฅผ ๋ค ์ ์ฉํ๋ฉด ๋๋ค. ๊ทธ๋ฆฌ๊ณ buffer flush๋ฅผ ํ ๋ฒ์ ์งํํด์ฃผ๋ endl์ ์ฐ๋๊ฒ ์๋๋ผ ๊ฐํ๋ฌธ์ \n ์ฌ์ฉํด์ ํจ์จ์ ์ด๊ฒ ์ฝ๋ ์์ฑ
'C, C++ > ๐ฅ BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(C++)โ Sorting Upper-Beginner I - 1 Solvedโ (0) | 2024.11.14 |
---|---|
(C++)โ Math & Geometry Upper-Beginner I - 1 Solvedโ (0) | 2024.11.14 |
(C++) โ Number Theory Upper-Beginner I - 3 Solvedโ (0) | 2024.11.14 |
(C++) โ Implementation Upper-Beginner I - 8 Solvedโ (0) | 2024.11.13 |
(C++) โ Implementation Beginner I - 28 Solvedโ (0) | 2024.11.13 |
๋๊ธ