Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<string>
- using namespace std;
- int m,n,coun;
- char ar[100][100];
- struct node{
- char ch;
- int in;
- }p[10000];
- void floodfill(int a, int b,char k){
- if(a<0||b<0||a==m||b==n||ar[a][b]!=k)
- return;
- coun++;
- ar[a][b]='.';
- floodfill(a-1,b,k);
- floodfill(a+1,b,k);
- floodfill(a,b-1,k);
- floodfill(a,b+1,k);
- }
- bool fin(node a,node b){
- if(a.in>b.in)
- return true;
- if(a.in==b.in&&a.ch<b.ch)
- return true;
- return false;
- }
- int main()
- {
- int kas=0,i,j;
- while(scanf("%d%d",&m,&n)==2){
- if(m==0&&n==0)
- break;
- kas++;
- for( i=0;i<m;i++)
- cin>>ar[i];
- int lenth=0;
- for(i=0;i<m;i++){
- for(j=0;j<n;j++){
- if(ar[i][j]!='.'){
- coun=0;
- p[lenth].ch=ar[i][j];
- floodfill(i,j,ar[i][j]);
- p[lenth++].in=coun;
- }
- }
- }
- sort(p,p+lenth,fin);
- printf("Problem %d:\n",kas);
- for(i=0;i<lenth;i++)
- printf("%c %d\n",p[i].ch,p[i].in);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement