[Solution]《键盘》解题报告

http://www.tyvj.cn/Open_Problem_Show.aspx?id=1007
其实这道题根本不需要像题目中提示说的那样复杂,不需要switch / case语句。

上代码:

#include <iostream>
#include <stdio.h>

using namespace std;

int x,y;
const int mx = 4, my = 11;
char c[mx][my]={
  {'1','2','3','4','5','6','7','8','9','0','-'},
  {'Q','W','E','R','T','Y','U','I','O','P'},
  {'A','S','D','F','G','H','J','K','L'},
  {'Z','X','C','V','B','N','M',','}
};

void getLoacltion(char n){
  for (int i = 0; i < mx; i++){
    for (int k = 0; k < my; k++){
      if (c[i][k] == n){
        x = i;y = k;
        return;
      }
    }
  }
}

int main(){
  char n;
  n = getchar();
  getLoacltion(n);
  cout << c[x-1][y] << " " << c[x-1][y+1];

  return 0;
}

就这么简单!

Leave a Reply

Your email address will not be published. Required fields are marked *