U E D R , A S I H C RSS

Jolly Jumpers/김태진

Status

Memory184KTime110MS
구현: 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;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:34
Processing time 0.0108 sec