More actions
imported>jereneal20 No edit summary |
(Repair batch-0002 pages from live compare) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
== Status == | == Status == | ||
{| class="wikitable" | {| class="wikitable" style="width:100%;" | ||
|- | |- | ||
| Memory | | Memory | ||
| Line 10: | Line 10: | ||
| | | | ||
| | | | ||
| 구현: | | 구현: 1시간, 입출력 및 디버깅:4시간 | ||
|} | |} | ||
== Source Code == | == Source Code == | ||
#include <stdio.h> | #include <stdio.h> | ||
int jolly(int A | int jolly(int A[], int val, int B[]); | ||
int bubbleSort(int A | int bubbleSort(int A[], int n); | ||
int main() | int main() | ||
{ | { | ||
int a | int a[3001]={0}; | ||
int b | int b[3001]={0}; | ||
int i,val,result; | int i,val,result; | ||
| Line 28: | Line 28: | ||
if(feof(stdin)) break; | if(feof(stdin)) break; | ||
for(i=0;i<val;i++){ | for(i=0;i<val;i++){ | ||
scanf("%d",&a | scanf("%d",&a[i]); | ||
} | } | ||
if(val==1) { | if(val==1) { | ||
| Line 43: | Line 43: | ||
} | } | ||
int jolly(int A | int jolly(int A[], int val, int B[]) | ||
{ | { | ||
int x=0,j; | int x=0,j; | ||
for(j=0;j<val-1;j++){ | for(j=0;j<val-1;j++){ | ||
B | B[j]=((A[j]-A[j+1])>0?(A[j]-A[j+1]):-(A[j]-A[j+1])); | ||
} | } | ||
//두개의 값사이의 차를 B함수에 넣음. | //두개의 값사이의 차를 B함수에 넣음. | ||
bubbleSort(B, val); | bubbleSort(B, val); | ||
if(B | if(B[0]!=1) return -100; | ||
for(j=0;j<val-2;j++){ | for(j=0;j<val-2;j++){ | ||
if(B | if(B[j+1]-B[j]==1) x+=1; | ||
} | } | ||
| Line 61: | Line 61: | ||
int bubbleSort(int C | int bubbleSort(int C[], int n) | ||
{ | { | ||
int i,j,temp; | int i,j,temp; | ||
for(i=n-2;i>=1;i--){ | for(i=n-2;i>=1;i--){ | ||
for(j=0;j<i;j++){ | for(j=0;j<i;j++){ | ||
if(C | if(C[j]>C[j+1]){ | ||
temp=C | temp=C[j]; | ||
C | C[j]=C[j+1]; | ||
C | C[j+1]=temp; | ||
} | } | ||
} | } | ||
| Line 77: | Line 77: | ||
return 0; | return 0; | ||
} | } | ||
Latest revision as of 00:16, 27 March 2026
Status
| Memory | 184K | Time | 110MS |
| 구현: 1시간, 입출력 및 디버깅:4시간 |
Source Code
#include <stdio.h>
int jolly(int A[], int val, int B[]);
int bubbleSort(int A[], int n);
int main()
{
int a[3001]={0};
int b[3001]={0};
int i,val,result;
while(1){
scanf("%d",&val);
if(feof(stdin)) break;
for(i=0;i<val;i++){
scanf("%d",&a[i]);
}
if(val==1) {
printf("Jolly\n");
if(feof(stdin)) break;
continue;
}
result=jolly(a,val,b);
if(result==val-2) printf("Jolly\n");
else printf("Not jolly\n");
if(feof(stdin)) break;
}
return 0;
}
int jolly(int A[], int val, int B[])
{
int x=0,j;
for(j=0;j<val-1;j++){
B[j]=((A[j]-A[j+1])>0?(A[j]-A[j+1]):-(A[j]-A[j+1]));
}
//두개의 값사이의 차를 B함수에 넣음.
bubbleSort(B, val);
if(B[0]!=1) return -100;
for(j=0;j<val-2;j++){
if(B[j+1]-B[j]==1) x+=1;
}
return x;
}
int bubbleSort(int C[], int n)
{
int i,j,temp;
for(i=n-2;i>=1;i--){
for(j=0;j<i;j++){
if(C[j]>C[j+1]){
temp=C[j];
C[j]=C[j+1];
C[j+1]=temp;
}
}
}
return 0;
}