https://www.acmicpc.net/problem/2750
2750๋ฒ: ์ ์ ๋ ฌํ๊ธฐ
์ฒซ์งธ ์ค์ ์์ ๊ฐ์ N(1 ≤ N ≤ 1,000)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์๋ ์๊ฐ ์ฃผ์ด์ง๋ค. ์ด ์๋ ์ ๋๊ฐ์ด 1,000๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์ ์์ด๋ค. ์๋ ์ค๋ณต๋์ง ์๋๋ค.
www.acmicpc.net
1. ๋ฌธ์
2. ์ ๋ ฅ
3. ์ถ๋ ฅ
์ฒซ์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํ ๊ฒฐ๊ณผ๋ฅผ ํ ์ค์ ํ๋์ฉ ์ถ๋ ฅํ๋ค.
4. ๋ฌธ์ ํ์ด
https://www.programiz.com/dsa/bubble-sort
Bubble Sort (With Code in Python/C++/Java/C)
Bubble Sort In this tutorial, you will learn about the bubble sort algorithm and its implementation in Python, Java, C, and C++. Bubble sort is a sorting algorithm that compares two adjacent elements and swaps them until they are in the intended order. Jus
www.programiz.com
์ฌ๋ฌ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํด๊ฒฐ๋ฒ ์ค ๊ธฐ๋ณธ์ธ ๋ฒ๋ธ์ ๋ ฌ๋ก ํด๊ฒฐํ๋ค. ์๊ณ ๋ฆฌ์ฆ์ ํ์๊ธฐ ๋๋ฌธ์ ๋๋๋ก ๊ฐ๋ ์ ์ดํดํ๊ณ ๋ฌธ์ ์ ์ ์ฉํด๋ณด๋ ค๊ณ ํ๋ค.
1. ์ฒ์ ์์ํ ๋๋ ๊ฐ๋ ์ ์ดํดํ๊ณ
2. ์ข ์ด์๋ค๊ฐ ์๊ณ ๋ฆฌ์ฆ์ ์ ์ดํดํ๋์ง ์์๋๋ก ์จ๋ณด๋ฉด์
3. ์ด์ค for๋ฌธ์ ์ ์ฉํ์๋ ์ ์ผ ํท๊ฐ๋ฆฌ๋ i์ j ์์์ ์์, ๋ง์ง๋ง ์ซ์๋ค์ ํ์ธํ๋ค.
๐๐ ์๊ณ ๋ฆฌ์ฆ ๋ ํ ์ฌ์ดํธ๋ ๋ธ๋ก๊ทธ์ ์ ๋ฆฌํ ํฌ์คํ ์ ์ฐธ๊ณ !! ๐๐
'๊ฟํ ๋ชจ์/ํ๋ก๊ทธ๋๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๊ธ ๋ชฉ๋ก
arty6848.tistory.com
C code
#include <stdio.h>
int main()
{
int test;
int tmp;
scanf("%d",&test);
int number[test];
for(int i=0; i<test; i++){
scanf("%d",&number[i]);
}
for(int i=0; i<test-1; i++){
for(int j=0; j<test-1-i; j++){
if(number[j]>number[j+1]){
tmp = number[j];
number[j] = number[j+1];
number[j+1]=tmp;
}
}
}
for(int i=0; i<test; i++){
printf("%d\n",number[i]);
}
return 0;
}