끄적끄적 코딩
article thumbnail
[C++] 백준 10871번 X보다 작은 수
알고리즘 2019. 3. 5. 14:32

배열 z에 값들을 넣고 y보다 작을 경우 배열 t에서 체크를 합니다. 0~10000의 범위에 있기때문에 t[10000]을 만들어주고 -1로 초기화해주었습니다. 그리고 z[i]가 y보다 작으면 t[c++] = z[i]를 해줍니다. 값의 비교가 끝났으면 배열 t에 있는 값들을 출력합니다. #include using namespace std; int main(int argc, char * argv[]) { int x, y, z[10000], t[10000], c = 0; cin >> x; cin >> y; for (int i = 0; i > z[i]; if (z[i] < y) { t[c++] = ..

article thumbnail
[C++] 백준 10817번 세 수
알고리즘 2019. 3. 5. 14:17

if문을 이용해서 문제를 풀었습니다. #include using namespace std; int main(int argc, char * argv[]) { int x, y, z; cin >> x; cin >> y; cin >> z; if (x >= y && y >= z || z >= y && y >= x) { cout = z || z >= x && x >= y) { cout = y || y >= z && z >= x) { cout

article thumbnail
[C++] 백준 9498번 시험 성적
알고리즘 2019. 3. 5. 14:13

if문을 이용해서 문제를 풀었습니다. #include using namespace std; int main(int argc, char * argv[]) { int x; cin >> x; if(x>=90){ cout

article thumbnail
[C++] 백준 15552번 빠른 A+B
알고리즘 2019. 3. 5. 14:05

빠른 시간에 문제를 풀어야 합니다. cin과 cout보다 printf와 scanf가 속도가 빠릅니다. #include #include using namespace std; int main(int argc, char * argv[]) { int c=0; int x, y; scanf("%d", &c); for (int i = 0; i < c; i++) { scanf("%d", &x); scanf("%d", &y); printf("%d\n", x + y); } return 0; }

article thumbnail
[C++] 백준 11721번 열 개씩 끊어 출력하기
알고리즘 2019. 3. 5. 14:02

string에 입력을 받은 후 substr 함수로 10글자씩 잘라서 출력합니다. #include #include using namespace std; int main(int argc, char * argv[]) { string s; cin >> s; int ten = s.size() / 10; int won = s.size() % 10; for (int i = 1; i

article thumbnail
[C++] 백준 11720번 숫자의 합
알고리즘 2019. 3. 5. 13:52

입력된 값들의 숫자를 하나하나 더해서 출력하는 문제입니다. int나 double로 받게 될 경우 범위를 넘는 경우가 생길 수 있어서 string으로 입력을 받았습니다. stoi함수를 이용해서 string을 int로 바꾸고 substr함수로 한 글자씩 잘라서 sum에 추가해주었습니다. #include #include using namespace std; int main(int argc, char * argv[]) { int a; int i = 0; string s; int sum = 0; cin >> a; cin >> s; for (int i = 1; i

article thumbnail
[C++] 백준 8393번 합
알고리즘 2019. 3. 5. 13:31

for문을 이용해서 문제를 풀었습니다. 입력한 값이 될때까지 i를 증가하면서 더합니다. #include #include using namespace std; int main(int argc, char *argv[]) { int x=0, value=0; cin >> x; for(int i=0; i

article thumbnail
[C++] 백준 1924번 2007년
알고리즘 2019. 3. 5. 13:27

month에 월, d에 일을 입력 받습니다. 그리고 d에 month를 day로 변환한값을 더한 후 switch문으로 요일을 판별합니다. #include using namespace std; int main(int argc, char *argv[]) { int m[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int d = 1; int month = 1; cin >> month; cin >> d; for (int i = 0; i < month; ++i) { d += m[i]; } switch (d % 7) { case 0: cout

검색 태그