zoukankan      html  css  js  c++  java
  • cf 6B

    B. President's Office
    time limit per test
    2 seconds
    memory limit per test
    64 megabytes
    input
    standard input
    output
    standard output

    President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.

    The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.

    Input

    The first line contains two separated by a space integer numbers nm (1 ≤ n, m ≤ 100) — the length and the width of the office-room, andc character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.

    Output

    Print the only number — the amount of President's deputies.

    Sample test(s)
    input
    3 4 R
    G.B.
    .RR.
    TTT.
    output
    2
    input
    3 3 Z
    ...
    .H.
    ..Z
    output
    0
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    int n,m,b[2500],ans;
    char c,s[110][110];
    int main()
    {
         cin>>n>>m>>c;
         for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                      cin>>s[i][j];
         for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                      if(s[i][j]==c)
                      {
                            b[s[i-1][j]]=1;
                            b[s[i][j-1]]=1;
                            b[s[i+1][j]]=1;
                            b[s[i][j+1]]=1;
                      }
          for(char i='A';i<='Z';i++) ans+=b[i];
          cout<<ans-b[c]<<endl;
          return 0;
    }
    

      

  • 相关阅读:
    0607pm克隆&引用类&加载类&面向对象串讲&函数重载
    0607am抽象类&接口&析构方法&tostring&小知识点
    静态
    面向对象--继承和多态
    面向对象的三个特性:封装
    ALV可输入状态下输入金额字段变小数的问题
    退出程序是跳过屏幕自检 比如 必输 EXIT-COMMAND
    ALV的报表对用户定义格式的控制(ALV I_SAVE)
    获利能力分析COPA的BAPI:BAPI_COPAACTUALS_POSTCOSTDATA 通过增强返回凭证号
    一个使用CDS VIEW 的 DEMO
  • 原文地址:https://www.cnblogs.com/a972290869/p/4222444.html
Copyright © 2011-2022 走看看