/* 나혼자 푼 천단위 세기
#include <stdio.h>
#include <string.h>
char stack [300];
int top;
int count = 0;
void initialize ()
{
top = -1;
}
void push(char a)
{
count++;
if (count%3 == 0)
{
top++;
stack[top] = a;
top++;
stack[top] = ',';
}
else
{
top++;
stack[top] = a;
}
}
void pop ()
{
printf("%c", stack[top]);
top--;
}
int main()
{
int n;
int i;
char a[201]; // stack[]이 문자를받을거기때문에
scanf("%d ", &n); //문자열 스페이스바 입력 주의
for (i=0; i<n; i++)
{
scanf("%c", &a[i]);
} //12 421 421
if (n<=3)
{
for (i=0;i<n;i++)
{
printf("%c", a[i]);
}
}
else
{
initialize();
for (i=n-1; i>=0; i--) //124, 124 ,21
{
push (a[i]);
}
if (n%3 == 0)
{
top--;
for (i=top;i>=0;i--)
{
pop();
}
}
else
{
for (i=top;i>=0;i--)
{
pop();
}
}
}
}
*/
/*
#include <stdio.h>
#include <string.h>
int stack[201];
int top = -1;
void push (int a)
{
top++;
stack[top] = a;
}
void pop(char a)
{
if (a=='+')
{
stack[top-1] = stack[top] + stack[top-1];
top--;
}
else if (a=='-')
{
stack[top-1] = stack[top-1] - stack[top];
top--;
}
else if (a=='*')
{
stack[top-1] = stack[top] * stack[top-1];
top--;
}
}
int main()
{
int i;
char a[201];
gets(a);
for (i=0;i<strlen(a);i++)
{
if (a[i]>=48 && a[i]<=57) //일의자리
{
push (a[i]-48);
}
else if (a[i]== '*' || a[i] == '-' || a[i] == '+');
{
pop(a[i]);
}
}
printf("%d", stack[0]);
}
입력 23872937 19239 -
정답 23853698
출력결과 2
*/
#include <stdio.h>
void QuickSort(int a[], int start, int end)
{
int index;
if (start<end)
{
index = Partition(a, start, end);//index = pivot의위치
QuickSort(a, start, index-1);
QuickSort(a, index+1, end);
}
else
{
return ;
}
}
int Partition (int a[], int start, int end)
{
int pivot = a[end]; //끝부분이 피벗
int i;
int index = start;
int temp;
for (i=start; i<end; i++)
{
if (a[i]<pivot) //안들어옴 = 피벗보다 큰 애임, 즉 인덱스는 큰 애를 도맡음 , i는 작은애 찾으러감
{
temp = a[index];
a[index] = a[i];
a[i] = temp;
index++;
}
}
temp = a[index];
a[index] = a[end];
a[end] = temp;
return index;
}
int main()
{
int n, i, a[100000],a2[100000],j;
scanf("%d", &n);
for (i=0;i<n;i++)
{
scanf("%d", &a[i]);
}
for (i=0;i<n;i++)
{
a2[i] = a[i];
}
QuickSort(a,0, n-1);
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if (a2[i] = a[j])
{
printf("%d ", j);
break;
}
}
}
}