Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

JollyJumpers/김태진: Difference between revisions

From ZeroWiki
imported>jereneal20
No edit summary
 
(Repair batch-0002 pages from live compare)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Status ==
== Status ==
{| class="wikitable"
{| class="wikitable" style="width:100%;"
|-
|-
| Memory
| Memory
Line 6: Line 6:
| Time
| Time
| 110MS
| 110MS
|-
|
|
|
| 구현: 1시간, 입출력 및 디버깅:4시간
|}
|}
== Source Code ==
== Source Code ==
  #include <stdio.h>
  #include <stdio.h>
   
   
  int jolly(int A[], int val, int B[]);
  int jolly(int A[], int val, int B[]);
  int bubbleSort(int A[], int n);
  int bubbleSort(int A[], int n);
   
   
  int main()
  int main()
  {
  {
     int a[3001]={0};
     int a[3001]={0};
     int b[3001]={0};
     int b[3001]={0};
     int i,val,result;
     int i,val,result;
      
      
Line 24: 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[i]);
             scanf("%d",&a[i]);
         }
         }
         if(val==1) {
         if(val==1) {
Line 39: Line 43:
  }
  }
   
   
  int jolly(int A[], int val, int B[])
  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[j]=((A[j]-A[j+1])>0?(A[j]-A[j+1]):-(A[j]-A[j+1]));
         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[0]!=1) return -100;
     if(B[0]!=1) return -100;
     for(j=0;j<val-2;j++){
     for(j=0;j<val-2;j++){
         if(B[j+1]-B[j]==1) x+=1;
         if(B[j+1]-B[j]==1) x+=1;
     }
     }
      
      
Line 57: Line 61:
   
   
   
   
  int bubbleSort(int C[], int n)
  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[j]>C[j+1]){
             if(C[j]>C[j+1]){
                 temp=C[j];
                 temp=C[j];
                 C[j]=C[j+1];
                 C[j]=C[j+1];
                 C[j+1]=temp;
                 C[j+1]=temp;
             }
             }
         }
         }
Line 73: 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;
}