์ ์ฒด ๊ธ
c++ ๋ฐฐ์ด ์ค๋ฆ์ฐจ์ ๋ด๋ฆผ์ฐจ์ ๊ตฌํ
๋ฐฐ์ด ์์ ์ฌ๋ฌ ๊ฐ์ด ๋ค์ฃฝ๋ฐ์ฃฝ ์์ฌ ์์ ๋, ์ด๊ฒ๋ค์ด ์ค๋ฆ์ฐจ์(์์ ๊ฐ์ด ๊ฐ์ฅ ์์ ์ค๊ณ ๋ฐฐ์ด ๋ท ์ธ๋ฑ์ค๋ก ๊ฐ์๋ก ์ธ๋ฑ์ค ๊ฐ์ด ์ปค์ง)์ผ๋ก ์ ๋ ฌ๋๋๋ก ์ด์คํฌ๋ฌธ์ ์จ์ ์ง์ ํ๋์ฝ๋ฉ์ผ๋ก ๊ตฌํํด๋ณด์๋ค. ๊ฐ์ข ์ ๋ ฌ ๊ธฐ๋ฒ์ ๋ฐฐ์ฐ๊ณ ๋๋ฉด ์ฝ๋๊ฐ ๋ฌ๋ผ์ง ๊ฒ์ด๋ค. #include using namespace std; int main() { int num[10] = { 986,4,7,12,45,895,3,7,34,5 }; for (int i =0; i+1
[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()](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb2HFvP%2FbtrftmOoPyZ%2FZgcUT1xsSATyn4ekQNSpvK%2Fimg.png)
[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
![2. [c++] ํน์ ๊ฐ ์ดํ์ ์ ์ค์์ ๊ฐ์ฅ ํฐ 2์ ๊ฑฐ๋ญ์ ๊ณฑ๋ง ๋ฐํํ๋ ํจ์๋ง๋ค๊ธฐ](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2F9a6Wq%2FbtrfoGmXgnf%2FpzNbK9cONFQxpDUZua0mak%2Fimg.png)
2. [c++] ํน์ ๊ฐ ์ดํ์ ์ ์ค์์ ๊ฐ์ฅ ํฐ 2์ ๊ฑฐ๋ญ์ ๊ณฑ๋ง ๋ฐํํ๋ ํจ์๋ง๋ค๊ธฐ
*์ง์ ์ง ๊ฒ์์ผ๋ก ๋ชฉ์ ์ ๋ณด๋ค ๋ ์ต์ ์ธ ํจ์๊ฐ ์กด์ฌํ ์ ์์ต๋๋ค.* - ํน์ ๊ฐ n์ ์์ ๋กญ๊ฒ ์ ๋ ฅํ๋ฉด, - n ์ดํ์ ์ ์ค์์ ๊ฐ์ฅ ํฐ 2์ ๊ฑฐ๋ญ์ ๊ณฑ๋ง์ ๋ฐํํ๋ ํจ์๋ฅผ ๋ง๋ค์ด๋ณด์๋ค. ์์) 100์ ๋ ฅ์ 64 ์ถ๋ ฅ 2์ ๋ ฅ์ 2์ถ๋ ฅ 1์ ๋ ฅ์ 1์ถ๋ ฅ #include using namespace std; int func(int* n) { int max =1; for (int i = 1; i * 2 > n; while (n > n; } int* a = &n; n = func(a); cout
Unity์์ this์ ์๋ฏธ
๋ณดํต ์คํฌ๋ฆฝํธ๋ ์ค๋ธ์ ํธ์ ๋ฃ๊ณ ์ด๋ค. this๋ ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํ๊ณ ์๋ ์ค๋ธ์ ํธ ๊ทธ ์์ฒด๋ฅผ ์๋ฏธํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์๋ ์์ 1๊ณผ ์์ 2๋ฅผ ์์ฑํ๋ฉด, ๊ฒฐ๊ณผ์ ์ผ๋ก ๋๊ฐ์ ์๊ฐ์ ํจ๊ณผ๊ฐ ๋ํ๋๋ค. using System.Collections; using System.Collections.Generic; using UnityEngine; public class studyScript : MonoBehaviour { void Update() { float x = Input.GetAxis("Horizontal") * 0.05f; float y = Input.GetAxis("Vertical") * 0.05f; this.transform.Translate(new Vector2(x, y)); } } using Sys..
Unity ๋์ ์์ฑ์ Random.Range๋ฅผ ํ์ฉํ์
float rnd = Random.Range(0.0f, 0.5f); 0.0f~0.5f ์ฌ์ด์ ์ซ์๋ฅผ ๋๋ค์ผ๋ก ์์ฑํ์ฌ ๋ณ์ rnd์ ๋ฃ์ด์ฃผ๋ ์ฝ๋์ด๋ค. ์๋ ์์ค์ฝ๋๋ A๋ฅผ ๋๋ฅผ ์, 0.0~0.5 ์ฌ์ด์ ๋์๋ฅผ ์์ฑํ์ฌ ๊ฐ์ ๋ณ์ rnd์ ์ ์ฅํ๊ณ ์ค๋ธ์ ํธ์ transform.position์ Vector3ํ z๊ฐ์ ๋์ ํด ์์น๋ฅผ ๋ฐ๊พธ๋ ์ฝ๋ using System.Collections; using System.Collections.Generic; using UnityEngine; public class studyScript : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.A)) { float rnd = Random.Range(0.0f, ..