Advertisement
mbah_bejo

TOWER WILDAN

Nov 7th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. int n;
  3.    
  4. int cekan(int map[][n],int posx,int posy, int luas)
  5. {
  6.     int tanda=0,i,i1,i2,i3=0, i4,i5=0;
  7.     int awal,awal1;
  8. //  bawah
  9.     for( i=posx+1;i<luas;i++)
  10.     {  
  11.     if(map[posy][i] == 1){
  12.          tanda++;
  13.          //map[posy][i] = 9;
  14.          //printf("%d",1);
  15.         if(tanda>0){
  16.             //printf("%d\n",tanda);
  17.         return tanda;
  18.     }
  19.     }
  20. }
  21.    
  22.     //atas
  23.         for(i1=posy-1;i1>=0;i1--)
  24.     {  
  25.     if((map[i1][posx]) == 1){
  26.         tanda++;
  27.         //map[i1][posx] = 9;
  28.     //  printf("%d",tanda);
  29.         if(tanda>0) {
  30.         //printf("%d\n",tanda);
  31.          return tanda;}
  32.     }
  33.     }
  34.     //return tanda;
  35.    
  36.    
  37.     // ler kiri bawah
  38.     i3=posx-1;
  39.     for(i2=posy-1;i2>=0;i2--)
  40.     {  
  41.     if(map[i2][i3] == 1 ){
  42.         tanda++;
  43.         //printf("%d %d\n",i3,i2);
  44.         //map[i2][i3] = 9;
  45.     }if(i3>1)i3--;
  46.     else break;
  47.         if(tanda>0)
  48.         {
  49.             //printf("%d\n",tanda);
  50.         return tanda;
  51.         }
  52.         //printf("%d",tanda);
  53.     }
  54.    
  55.     //ler kiri atas
  56.     i5=posx+1;
  57.     for(i4=posy-1;i4>=0;i4--)
  58.     {  
  59.     if(map[i4][i5] == 1 ){
  60.         tanda++;
  61.         //printf("%d %d\n",i5,i4);
  62.         //map[i4][i5] = 8;
  63.     }
  64.     if(i5<luas-1)
  65.     {
  66.     i5++;
  67.     } else break;
  68.    
  69.         if(tanda>0)
  70.         {
  71.         //printf("%d\n",tanda);
  72.         return tanda;  
  73.         }
  74.     }
  75.    
  76.    
  77.     return tanda;
  78.     }
  79. //}
  80.  
  81.  
  82.  
  83. int main()
  84. {
  85.     int i,x,y,tot=0,awal,awal1;
  86.    
  87.     scanf("%d",&n);
  88.     int map[n][n];
  89.    
  90. for(awal=0;awal<n;awal++)
  91.     {
  92.         for(awal1=0;awal1<n;awal1++) map[awal][awal1]=0;
  93.    
  94.     }
  95.    
  96.     for(i=0;i<n;i++)
  97.     {
  98.         scanf("%d%d",&x,&y);
  99.         map[y][x]=1;
  100.         tot+=cekan(map,x,y,n);
  101.         x=0;y=0;
  102.     }
  103.    
  104.     //printf(" %d__",tot);
  105.    
  106.         (tot<=1) ? printf("Tidak Ada\n") : printf("Ada\n");
  107. }
  108.  
  109.    
  110.    
  111.     /*
  112. 8
  113. 5 0
  114. 3 1
  115. 6 2
  116. 0 3
  117. 6 4
  118. 1 5
  119. 4 6
  120. 2 7
  121.  
  122.  
  123.  
  124.  
  125.         0   1   2   3   4   5   6   7
  126.     0   x   x   x   x   x   T   x   x
  127.     1   x   x   x   T   x   x   x   x
  128.     2   x   x   x   x   x   x   T   x
  129. Y   3   T   x   x   x   x   x   x   x
  130.     4   x   x   x   x   x   x   x   T
  131.     5   x   T   x   x   x   x   x   x
  132.     6   x   x   x   x   T   x   x   x
  133.     7   x   x   T   x   x   x   x   x
  134. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement