Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int d=0, x, y;
- char langkah[100][100];
- int tes(int x, int y, char buah)
- {
- if(langkah[x][y]!=buah) return d;
- langkah[x][y]='-';
- tes(x+1,y,buah);
- tes(x-1,y,buah);
- tes(x,y+1,buah);
- tes(x,y-1,buah);
- d++;
- return d;
- }
- int main()
- {
- int p,q;
- scanf("%d %d",&x, &y);
- for (p=0;p<x;p++)
- {
- for (q=0;q<y;q++)
- {
- scanf("%c",&langkah[p][q]);
- }
- getchar();
- }
- int hargaA=0, hargaJ=0, hargaM=0, hargaS=0;
- int luasA, luasJ, luasM, luasS;
- for(p=0;p<x;p++)
- {
- for(q=0;q<y;q++)
- {
- {
- luasA=tes(p,q,'A');
- hargaA+=(luasA*luasA)*500;
- d=0;
- }
- {
- luasJ=tes(p,q,'J');
- hargaJ+=(luasJ*luasJ)*500;
- d=0;
- }
- {
- luasM=tes(p,q,'M');
- hargaM+=(luasM*luasM)*500;
- d=0;
- }
- {
- luasS=tes(p,q,'S');
- hargaS+=(luasS*luasS)*500;
- d=0;
- }
- }
- }
- printf("%d\n", hargaA);
- printf("%d\n", hargaJ);
- printf("%d\n", hargaM);
- printf("%d\n", hargaS);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement