C++/c++

    c++ vector /pair / sort ์‚ฌ์šฉ ์˜ˆ์ œ

    #include #include #include using namespace std; int main() { vector v; v.push_back(pair(1,"ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค")); v.push_back(pair(3, "๋ฐฑ์ค€")); v.push_back(pair(2, "๊ฟ€์žผ")); sort(v.begin(), v.end()); for (int i = 0; i

    [c++] std::array / try catch / auto element ์—ฐ์Šต ์˜ˆ์ œ

    ์˜ˆ์ œ #include #include using namespace std; void print(arrayarr) { for (auto ele : arr) cout

    [c++] ์ฝ”๋”ฉํ…Œ์ŠคํŠธ์—์„œ ios::sync_with_stdio; cin.tie(0); ๋ฅผ ์“ฐ๋ฉด ์ข‹์€ ์ด์œ 

    ์ž…์ถœ๋ ฅ์‹œ์— printf ๋ฐ scanf๋ฅผ ์“ฐ์ง€ ์•Š๊ณ  cout ๋ฐ cin์œผ๋กœ๋งŒ ์ž…์ถœ๋ ฅ์„ ํ•  ์ƒ๊ฐ์ด๋ผ๋ฉด, ios::sync_with_stdio(0); cin.tie(0); ๋ฅผ ์จ์ฃผ๋ฉด ์ข‹๋‹ค. ์ž…์ถœ๋ ฅ ์–‘์ด ๋งŽ์•„์ง€๋”๋ผ๋„ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œ์ผœ์ฃผ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์‚ฌ์šฉ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์ด cin๊ณผ cout ํ•˜๊ธฐ ์ „์— main ํ•จ์ˆ˜์—์„œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด๋‹ค. int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; getline(cin,s); cout ์ž…๋ ฅ์„ ํ•  ๋•Œ์— ๋งˆ์ง€๋ง‰ ์ž…๋ ฅ์„ ํ•˜๊ธฐ ์ „์— ์ถœ๋ ฅ ๋ฒ„ํผ๋ฅผ ๋น„์›Œ์ฃผ๊ฒŒ ๋œ๋‹ค. stream์„ tieํ•˜๋ฉด ๋‹ค๋ฅธ stream์—์„œ ์ž…์ถœ๋ ฅ์š”์ฒญ์ด ์˜ค๊ธฐ์ „์— stream์„ flush๋œ๋‹ค๋Š” ๊ฒƒ์„ ์ดํ•ดํ•œ๋‹ค๋ฉด cin.tie(0);..

    [c++] ๊ณต๋ฐฑ์„ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜๊ธฐ ์ข‹์€ ํ•จ์ˆ˜ getline()

    [c++] ๊ณต๋ฐฑ์„ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜๊ธฐ ์ข‹์€ ํ•จ์ˆ˜ getline()

    ์ผ๋ฐ˜ string ๋ณ€์ˆ˜์— ๊ณต๋ฐฑ์„ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚œ๋‹ค. ๊ฐ€๋ น ์•„๋ž˜์™€ ๊ฐ™์€ main ํ•จ์ˆ˜์—์„œ k์— [๊ณต๋ฐฑ์„ ํฌํ•จํ•œ ๋ฌธ์ž์—ด] ์ด๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚œ๋‹ค. int main() { string k; cin >> k; cout

    c++ ํŠน์ • ํ•จ์ˆ˜์˜ ์ธ์ž๋กœ ๋ฐฐ์—ด์ฃผ์†Œ๋ฅผ ๋„˜๊ธฐ๋ฉด?

    ์ฃผ์†Œ๋ฅผ ๋„˜๊ฒผ๊ธฐ ๋•Œ๋ฌธ์— funcํ•จ์ˆ˜๊ฐ€ ๋๋‚˜๊ณ  ๋ฉ”์ธํ•จ์ˆ˜๋กœ ๋Œ์•„๊ฐ€๋„ funcํ•จ์ˆ˜์—์„œ ์ดˆ๊ธฐํ™”ํ•œ ๊ฐ’์œผ๋กœ ์ถœ๋ ฅ๋œ๋‹ค. #include using namespace std; void func(int arr[]) { arr[0] = 10; } int main() { int arr[3] = { 1,2,3 }; func(arr); cout

    #include <conio.h> _getch() ์„ค๋ช…๊ณผ ์ฝ”๋“œ ์˜ˆ์‹œ

    #include ์ฝ˜์†” input output ํ—ค๋”ํŒŒ์ผ์ด๋‹ค. ์ฝ˜์†”์ฐฝ์—์„œ ์ž…์ถœ๋ ฅํ•˜๋Š” ๊ธฐ๋Šฅ๋“ค์„ ์ œ๊ณตํ•ด์ฃผ๋Š” ํ—ค๋”ํŒŒ์ผ์ด๋‹ค. _getch() _getch() ํ•จ์ˆ˜๋Š” ๋ฌธ์ž 1๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š” ํ•จ์ˆ˜์ด๋‹ค. Enter๋ฅผ ์น˜์ง€ ์•Š๋”๋ผ๋„ ๋ฌธ์ž๋ฅผ ๋ˆ„๋ฅด๋Š” ์ˆœ๊ฐ„ ๋ฐ”๋กœ ๊ทธ ๋ฌธ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์ข…๋ฃŒ๋œ๋‹ค. ๋‹ค์‹œ ๋งํ•ด, cin ์ฒ˜๋Ÿผ ์ž…๋ ฅํ•œ ๋’ค์— ๊ตณ์ด ์—”ํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•  ํ•„์š”์—†์ด ์ž…๋ ฅ ํ™•์ธํ•ด์ค€๋‹ค. ํ‚ค๋ณด๋“œ์—์„œ q๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ ๊ฒŒ์ž„ ์ข…๋ฃŒํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์ž‘์„ฑํ•˜๋Š” ์ฝ”๋“œ #include #include #include using namespace std; int main(){ while(true){ char key = _getch(); if(key=='q'|| key=='Q') break; } cout

    [C++] ๋กœ๋˜ ์ฝ”๋”ฉ LOTTO

    #include #include using namespace std; int main() { srand((unsigned int)time(0)); int Lotto[45] = {}; for (int i = 0; i