11244 – Counting Stars

Problem Link

#Solution

#include<cstdio>
using namespace std;
int dx[]={-1,1,0,0,-1,1,-1,1};
int dy[]={0,-1,1,-1,-1,1,1,0};
int main()
{
int n,m,c,tx,ty,res;
while(scanf(“%d %d”,&n,&m)==2 && n &&m)
{

int i,j,k;
res=0;
char vis[105][105]={0};
for(i=0;i<n;i++)
scanf(“%s”,vis[i]);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{c=1;
if(vis[i][j]==’*’)
{

for(c=0,k=0;k<8;k++)
{
tx=i+dx[k];
ty=j+dy[k];
if(tx>=0 &&ty>=0 &&tx<n &&ty<m &&vis[tx][ty]==’*’)
c++;

}

}
if(c==0) res++;

}
}
printf(“%d\n”,res);
}

return 0;
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized, uva and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s