Advertisement
Guest User

Kebun

a guest
Nov 26th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int d=0, x, y;
  4. char langkah[100][100];
  5.  
  6. int tes(int x, int y, char buah)
  7. {
  8.     if(langkah[x][y]!=buah) return d;
  9.     langkah[x][y]='-';
  10.     tes(x+1,y,buah);
  11.     tes(x-1,y,buah);
  12.     tes(x,y+1,buah);
  13.     tes(x,y-1,buah);
  14.     d++;
  15.     return d;
  16. }
  17.  
  18. int main()
  19. {
  20.     int p,q;
  21.     scanf("%d %d",&x, &y);
  22.     for (p=0;p<x;p++)
  23.     {
  24.         for (q=0;q<y;q++)
  25.         {
  26.             scanf("%c",&langkah[p][q]);
  27.         }
  28.         getchar();
  29.     }
  30.    
  31.     int hargaA=0, hargaJ=0, hargaM=0, hargaS=0;
  32.     int luasA, luasJ, luasM, luasS;
  33.     for(p=0;p<x;p++)
  34.     {
  35.         for(q=0;q<y;q++)
  36.         {
  37.             {
  38.                 luasA=tes(p,q,'A');
  39.                 hargaA+=(luasA*luasA)*500;
  40.                 d=0;
  41.             }
  42.             {
  43.                 luasJ=tes(p,q,'J');
  44.                 hargaJ+=(luasJ*luasJ)*500;
  45.                 d=0;
  46.             }
  47.             {
  48.                 luasM=tes(p,q,'M');
  49.                 hargaM+=(luasM*luasM)*500;
  50.                 d=0;
  51.             }
  52.             {
  53.                 luasS=tes(p,q,'S');
  54.                 hargaS+=(luasS*luasS)*500;
  55.                 d=0;
  56.             }
  57.         }
  58.     }
  59.     printf("%d\n", hargaA);
  60.     printf("%d\n", hargaJ);
  61.     printf("%d\n", hargaM);
  62.     printf("%d\n", hargaS);
  63.    
  64. return 0;  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement