1517번 - 버블 소트
#include<stdio.h>int main(){ int i, j, temp; int x = 0; int n; char str[100]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%c", &str[i]); } for (i = 0; i < n; i++) { for (j = 0; j < n - i - 1; j++) { if (str[j] < str[j + 1]) { temp = str[j]; str[j] = str[j + 1]; str[j + 1] = temp; } x++; } } printf("%d\n", x); return 0;}
왜 런타임 에러가 뜨는지 모르겠습니다.
더 이상 드릴 말씀이 없군요. 문제의 조건은 읽어보셨나요?
댓글을 작성하려면 로그인해야 합니다.
acruxdy 5년 전
#include<stdio.h>
int main()
{
int i, j, temp;
int x = 0;
int n;
char str[100];
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%c", &str[i]);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (str[j] < str[j + 1])
{
temp = str[j];
str[j] = str[j + 1];
str[j + 1] = temp;
}
x++;
}
}
printf("%d\n", x);
return 0;
}
왜 런타임 에러가 뜨는지 모르겠습니다.