๐ป/C++9 [c++] replace() ํจ์, find() ํจ์ / ๋ฌธ์์ด ์ฐพ๊ธฐ 1. size_tint ํ: -21e8 ~ 21e8 ์ ์ size_t ํ : unsigned int ๋ '0์ ํฌํจํ ์์ ์ ์'๋ค.: ์ปดํจํฐ ์ฌ์์ ๋ฐ๋ผ uint32_t๊ฐ ๋ ์๋ ์๊ณ , uint64_t๊ฐ ๋ ์๋ ์๋ค. ex)uint32_t u32t; ๋ 32๋นํธ์ 0์ ํฌํจํ ์์ ์ ์unit64_t u64t; ๋ 64๋นํธ์ 0์ ํฌํจํ ์์ ์ ์ string::npos: size_t์ underflow ๊ฐ -> ์ฐ๋ ๊ธฐ๊ฐ 2. find() ํจ์C++ string ๋ณ์์์ ํน์ ๋ฌธ์์ด์ ์ฐพ์ ๋, std::string์ find() ํจ์๋ฅผ ์ฌ์ฉํ๋ค. #include #include using namespace std;int main(){ string s = "Enter ui1234 .. 2024. 11. 27. [c++] ๊ตฌ์กฐ์ฒด ๋ฐฑํฐ ํธ์๋ฐฑ , ์์์ ๋ฃ๊ธฐ /struct vector push_back ๊ตฌ์กฐ์ฒด (struct) : ๊ตฌ์กฐ์ฒด๋ ์ฌ์ฉ์๊ฐ ์ง์ ์๋ฃํ์ ์ง์ ํจ.์๋์ ๊ฐ์ด POS๋ผ๋ ์๋ฃํ์ ๊ตฌ์กฐ์ฒด๋ฅผ ํ์ฑํ ์ ์๋ค.struct POS{ int y,x; string name; }; ๊ตฌ์กฐ์ฒด ๋ฉค๋ฒ ์ ๊ทผ POS a, b; cin >> a.x >> a.y >> b.x >> b.y;:๋ฉ์ธ ํจ์์์ ์์ ๊ฐ์ด POS๋ผ๋ ์๋ฃํ์ ๋ฉค๋ฒ๋ณ์๋ฅผ ์ ์ธํ๊ณ , '.'๋ฅผ ์ฌ์ฉํด์ ์์ ๊ตฌ์กฐ์ฒด์ ํ์ฑํ ๊ฐ๋ณ ๋ฉค๋ฒ์ ์ ๊ทผํ ์ ์๋ค. ๊ตฌ์กฐ์ฒด์ ์์์ push_back ์๋์ ๊ฐ์ด ๊ตฌ์กฐ์ฒด๋ฅผ ์ฌ์ฉํด์ ์์์์ vector์ push_back ํ ์ ์๋ค. case 01#include #include using namespace std;struct POS{ int y, x;};int main(){ .. 2024. 7. 13. [c++] vector push_back๊ณผ emplace_back 1. push_back๊ณผ emplace_back์ ์ฐจ์ด push_back๊ณผ emplace_back์ vector์์ ๊ฐ์ฒด๋ฅผ ๋ฃ๋ ๋ฐฉ์์ ์ฐจ์ด๊ฐ ์๋ค. push_back() ํจ์๋ ๊ฐ์ฒด๋ฅผ ์ง์ด๋ฃ๋ ํ์์ด๋ค. ๋ฐ๋ผ์ ๊ฐ์ฒด๊ฐ ์๋ ์ํฉ์ด๋ผ๋ฉด '์์ ๊ฐ์ฒด'๊ฐ ์์ด์ผํ๋ค. ์ด๋ฏธ ๋ง๋ค์ด์ง ๊ฐ์ฒด๋ฅผ ๋ฃ๋ ํจ์์ธ ๊ฒ์ด๋ค. ์ด๋ ์ธ์๋ v์ ๋์ ๊ณ์ํด์ ์ถ๊ฐ๋๋ค.vectorv;for (int i = 0; i > a; v.push_back(a);}//v์ 5๊ฐ์ intํ ์ธ์๋ฅผ ๋ฐ์. ๋ฐ๋ฉด์ emplace_back()ํจ์์ ๊ฒฝ์ฐ, ํจ์๋ฅผ ๊ตฌ์ฑํ๋๋ฐ ํ์ํ ์ ๋ณด๋จผ์ ๋ฃ์ด์ฃผ๊ณ ํจ์ ๋ด์์ ๊ฐ์ฒด๋ฅผ ์์ฑํด์ ์ฝ์ ํ๋ ๋ฐฉ์์ด๋ค.ํจ์ ๋ด๋ถ์ ์์๊ฐ์ฒด๊ฐ ์์ฑ๋ผ์ ์๋ฆฌ๋ฅผ ์ก์์ค๋ค๋ ํน์ง์ ๊ฐ์ง๋ค. ๋ฐ๋ผ์ emplace_back(.. 2024. 6. 27. [c++] ๋ฐ์ฌ๋ฆผ / ์ฌ๋ฆผ / ๋ด๋ฆผ ํจ์ -ํค๋์[ ๋ฅผ ์ถ๊ฐํด์ผํ๋ค. ์ฌ๋ฆผํจ์: ceil() ๋ด๋ฆผํจ์: floor() ๋ฐ์ฌ๋ฆผํจ์: round() ๋ณ์์ ์๋ฃํ์ double๋ก ํด์ผ ๋ณ์ ์์ ์ค์๋ฅผ ๋ฃ์ ์ ์๋ค. ์์์ 2๋ฒ์งธ , 3๋ฒ์งธ ์๋ฆฌ๋ฅผ ๊ตฌํด๋ณด์, ์์์ 2๋ฒ์งธ ์๋ฆฌ๊น์ง ๋ฐ์ฌ๋ฆผ์์๋ฅผ 100๋ฐฐ ํ๋ค์ ๋ฐ์ฌ๋ฆผ ํ ๋๋๊ธฐ 1003๋ฒ์งธ ์๋ฆฌ๊น์ง๋์๋ฅผ 1000๋ฐฐ ํ๋ค์ ๋ฐ์ฌ๋ฆผ ํ ๋๋๊ธฐ 1000 ๋ฒ๋ฆผ๊ณผ ์ฌ๋ฆผ์ ๋ฐ์ฌ๋ฆผํจ์ round ๋์ ๊ฐ๊ฐ floor, ceil ํจ์๋ฅผ ๋ฃ์ผ๋ฉด ๋๋ค. 2024. 4. 11. [c++] DFS ๊น์ด ์ฐ์ ํ์ , ์ฌ๊ทํจ์ DFS: Depth - First Search (๊น์ด์ฐ์ ํ์)ํ์ฌ ์ง์ ์์ ์ ํด๋์ ์ง์ ๊น์ง ๋ ธ๋๋ฅผ ๊น๊ฒ ํ์ํ๋ ๋ฐฉ์์คํ ๋๋ ์ฌ๊ทํจ์๋ก ๊ตฌํํ๋ค. ์ฌ๊ทํจ์์๊ธฐ ์์ ์ ๊ณ์ํด์ ํธ์ถํ๋ค.์ด๊ธฐํ๋๋๋ ์กฐ๊ฑด (if๋ฌธ)๊ฐ์ง(branch) / ์ฌ๊ท์กฐ๊ฑด Q. ์ฌ๊ทํจ์ ์์๋ฌธ์ ์ซ์ n์ ์ ๋ ฅ ๋ฐ์ผ์ธ์.์ซ์ n๋ถํฐ 0๊น์ง Count down ํ๋ค๊ฐ๋ค์ ๋์์ค๋ ์๋ฅผ ์ถ๋ ฅ ํ์๋ฉด ๋ฉ๋๋ค.ex) 44 3 2 1 0 1 2 3 4ex ) 66 5 4 3 2 1 0 1 2 3 4 5 6 #includeusing namespace std;void abc(int num){ cout > n; abc(n); return 0;} ์์ ์ฌ๊ทํจ์๊ฐ ์ฌ์ฉ๋ ์ฝ๋๋ฅผ ์์๋ก ์ดํด๋ณด๋ฉด, 1. main ํจ์์์ ์ฌ๊ทํจ์์ ์ด๊ธฐ๊ฐ.. 2024. 4. 2. [c++] DAT DAT : ์ธ๋ฑ์ค์ ์๋ฏธ๋ฅผ ๋ถ์ฌํ๋ ํ ์ด๋ธ #include #include using namespace std;int dat[256]={0}; //๋ชจ๋ ๋ฌธ์(๊ธฐํธ,๋ฌธ์,์ซ์)๋ 256๊ฐ์ ์ซ์๋ก ํํ์ด ๊ฐ๋ฅํ๋ค.int main(){cout #include #include using namespace std;int dat[256]={0}; //๋ชจ๋ ๋ฌธ์(๊ธฐํธ,๋ฌธ์,์ซ์)๋ 256๊ฐ์ ์ซ์๋ก ํํ์ด ๊ฐ๋ฅํ๋ค.int main(){dat['A']++; //dat[65]++; ์๋ฏธ์ด๊ณ , ์ถ๋ ฅํ๋ฉด '1'์ด ์ถ๋ ฅ๋๋ค.return 0; } ๋ค์๊ณผ ๊ฐ์ด dat๋ฅผ ํตํด ๋ฌธ์์ด ๋ด๋ถ์ ํน์ ๋ฌธ์๊ฐ ๋ช ๋ฒ ๋ฑ์ฅํ๋์ง count ํด๋ณด์. #include #include using namespace std;in.. 2024. 3. 21. [c++] insertํจ์/ eraseํจ์/ sortํจ์/ swapํจ์ ์์ฃผ ์ฌ์ฉํ๋ vector๋๋ string ๋ด๋ถํจ์ ์ ๋ฆฌ ๐ก insert ํจ์ : ์์ ์ฝ์ insertํจ์๋ ๋ฌธ์์ด์ ์ค๊ฐ์ ๋ฌธ์๋ฅผ ์ถ๊ฐํด์ฃผ๋ ํจ์์ด๋ค.index์ ์์น์ ์ง์ด ๋ฃ๋๋ค = ์ฝ์ ๋๋ ๋ฌธ์์ด์ ์์ ์์น๊ฐ index๋ฒ์งธ์ฝ์ ์, index์์น์ ์๋ ๋ฌธ์๋ ์ฝ์ ๋๋ ๋ฌธ์์ด ๋งจ ๋ค๋ก ๋ฐ๋ฆฐ๋ค.vector v={1,2,3,4,5};vector iterator it;auto it= v.begin(); // it์ ์ด์ ๋ถํฐ v.begin()์ด๋ค.auto it(it + 1, 9) //vector::iterator it=v.begin(); v.insert(v.begin()+1 , 9); //v์ ์ฒซ ์ธ๋ฑ์ค๋ก๋ถํฐ 1์ถ๊ฐํ(v[1]) ์ธ๋ฑ์ค ์๋ฆฌ์ ์์'9' ์ฝ์ .. 2024. 3. 21. [c++] vector ์ ๋ฆฌ [ ๋ชฉ์ฐจ ]1. vector์ ๊ธฐ๋ณธ ํ๊ณผ ํน์ง2. vector ๋ฉค๋ฒ ํจ์๋ค ์ ๋ฆฌ3. 2์ฐจ์ vector 1. vector์ ๊ธฐ๋ณธ ํ๊ณผ ํน์ง vector[data type]>[๋ณ์์ด๋ฆ]ex) vector v ; vectorv;vectorv;ex) vectorv(5) = {1,2,3,4,5}; vector์ ์๋์ผ๋ก ๋ฉ๋ชจ๋ฆฌ๊ฐ ํ ๋น๋๋ ๋ฐฐ์ด์ด๋ค. (๋ฐฐ์ด ์ค์์ ์งฑ ์ ๋ฐฐ์ด ! )๋งจ ๋ค์ชฝ์์ ์ฝ์ ๊ณผ ์ญ์ ๊ฐ ๊ฐ๋ฅํจ. -> "v.push_back()" / "v.pop_back()" ํจ์๋ฅผ ์ฌ์ฉํจ.#include ํค๋ํ์ผ์ ์ถ๊ฐํด์ผํจ.vector์ ๋ณ์ ํฌ๊ธฐ๋งํผ ํ ๋น ํ ์ ์์.ex) int num1;cin>> num1; * int arr[num]= {0}; -> ์ค๋ฅvector v(.. 2024. 2. 18. [c++] ๋ณ์์ ํฌ์ธํฐ (pointer) c++ ์์ ๋ณ์๋ฅผ ์ ์ธํ๋ ๋ฐฉ์๊ณผ ๊ทธ๋ฆฌ๊ณ ๊ฐ ๋ฉ๋ชจ๋ฆฌ ๋ด๋ถ์ ๊ฐ์ ๋ถ๋ฌ์ค๊ธฐ ์ํ ํฌ์ธํฐ(pointer) ๊ธฐ๋ฅ์ ๋ํด ์ ๋ฆฌํด๋ณด์. 1. ๋ณ์ ๋ณ์๋ฅผ ์ด๋ป๊ฒ ์ ์ธํ๋ ์ง์ ๋ฐ๋ผ ๋ฉ๋ชจ๋ฆฌ ๋ด์ ์ ์ฅ๋๋ ๊ณณ์ด ๋ค๋ฅด๊ธฐ๋๋ฌธ์ ๋ณ์์ ์ธ์ ์ข ๋ฅ์ ๋ํด ์ ๋ฆฌํ๋ค. ๋ณ์๋ฅผ ์ ์ธํ๋ ๋ฐ์๋ '๋ณ์์ ์ ํจ ๋ฒ์(variable scope) '์ ๋ฐ๋ผ ๋ค์๊ณผ ๊ฐ์ด ๋ถ๋ฅํ ์ ์๋ค. 1. ์ง์ญ ๋ณ์(local variable) 2. ์ ์ญ ๋ณ์ (global variable) 3. ์ ์ ๋ณ์ (static variable) 4. ๋ ์ง์คํฐ ๋ณ์ (register variable) ์ ์ญ๋ณ์ ์ด๋ค ๋ณ์ ์์ญ ๋ด์์๋ ์ ๊ทผํ ์ ์๋ ๋ณ์ ์ด๋ค ์ค์ฝํ์์๋ ์ฐธ์กฐ๊ฐ๋ฅํ๋ฉฐ, ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํ๋ค. ๋ฉ๋ชจ๋ฆฌ์ ํ(heap) ์์ญ์ ํ ๋น๋จ. ์ง์ญ๋ณ์ '.. 2024. 2. 18. ์ด์ 1 ๋ค์