Created
August 20, 2018 08:51
-
-
Save hanjae-jea/1c277298a3e1afacacf4d868e6dbbc98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
int main() | |
{ | |
int a[10]; | |
for (int i = 0; i < 10; i++) { | |
scanf("%d", &a[i]); // scanf("%d", a+i) 랑 같은 코드 | |
} | |
// 배열의 이름만 써놓으면 배열의 주소가 되고, | |
std::sort(a, a + 10); // sort 함수 첫번째에는 배열의 주소, 두 번째에는 배열의 주소에다가 갯수 만큼 더한 주소를 집어넣으면 된다. | |
printf("a : "); | |
for (int i = 0; i < 10; i++) { | |
printf("%d ", a[i]); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
using namespace std; // 이제 std::sort 대신 sort 만 써도 정상 동작 | |
int main() | |
{ | |
int a[10]; | |
for (int i = 0; i < 10; i++) { | |
scanf("%d", &a[i]); // scanf("%d", a+i) 랑 같은 코드 | |
} | |
// 배열의 이름만 써놓으면 배열의 주소가 되고, | |
sort(a, a + 10); // sort 함수 첫번째에는 배열의 주소, 두 번째에는 배열의 주소에다가 갯수 만큼 더한 주소를 집어넣으면 된다. | |
printf("a : "); | |
for (int i = 0; i < 10; i++) { | |
printf("%d ", a[i]); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <algorithm> | |
using namespace std; // 이제 std::sort 대신 sort 만 써도 정상 동작 | |
bool cmp(int a, int b) { | |
return a > b; | |
} | |
int main() | |
{ | |
int a[10]; | |
for (int i = 0; i < 10; i++) { | |
scanf("%d", &a[i]); // scanf("%d", a+i) 랑 같은 코드 | |
} | |
sort(a, a + 10, cmp); // 비교하는 함수를 넣어서 내림차순으로 변경 | |
printf("a : "); | |
for (int i = 0; i < 10; i++) { | |
printf("%d ", a[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment