标签:
3 3 **. .3. *** 4 5 ***** ***.* **.2. **...
3/5 1/1
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<map> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define INF 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define ULL unsigned long long using namespace std; char s[100][100]; int a[100][100]; int i,j; int n,m; int main () { int x,y; int I,J; while(cin>>n>>m) { memset(a,0,sizeof(a)); int sum=0; int ans; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>s[i][j]; if(s[i][j]==‘*‘) { a[i][j]=1; } if(s[i][j]==‘.‘) { a[i][j]=2; } else if(s[i][j]>=‘1‘&&s[i][j]<=‘8‘) { a[i][j]=3; ans=s[i][j]-‘0‘; x=i; y=j; } } } for(I=x-1;I<=x+1;I++) { for(J=y-1;J<=y+1;J++) { if(a[I][J]==1) { sum++; } // cout<<a[I][J]; } // cout<<endl; } // cout<<sum<<endl; cout<<ans/__gcd(sum,ans)<<"/"<<sum/__gcd(sum,ans)<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5136547.html