CF 6 B. President's Office

题目:President's Office

思路:水 直接用map记录一下就ok

#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
bool vis[110][110];
char s[110][110];
map<char,int>mp;
int move[4][2]={1,0,-1,0,0,1,0,-1};
int main()
{
    mp.clear();
    int m,n;
    char boss;
    scanf("%d%d %c",&m,&n,&boss);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<m;i++)
    {
        getchar();
        for(int j=0;j<n;j++)
        {
            scanf("%c",&s[i][j]);
            if(s[i][j]==boss)
                vis[i][j]=1;
        }
    }
    int x,y;
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
        {
            if(vis[i][j])
            {
                for(int k=0;k<4;k++)
                {
                    x=i+move[k][0];
                    y=j+move[k][1];
                    if(x>=0&&y>=0&&x<m&&y<n&&!vis[x][y])
                    {
                        mp[s[x][y]]++;
                    }
                }
            }
        }
    map<char,int>::iterator it=mp.find('.');
    if(it!=mp.end())
        mp.erase(it);
    cout<<mp.size()<<endl;
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/overflow/p/3191367.html