zoukankan      html  css  js  c++  java
  • java算法 rqy

    题目描述

    rqy在和妹子约会,突然女票打来电话。rqy骗女票他在写代码。女票为了证实,问他键盘上F键左边是哪个键。
    你能否帮助rqy回应女票的质问?不然他可就要写思想汇报了...

    输入

    输入数据第一行是一个整数 T(1≤T≤10000),表示测试数据的组数。
    之后每一行先是一个大写字母X ,之后为一个字符串Left或Right,分别表示询问X键的左边或右边是哪个键。

    输出

    如果结果为一个字母键,输出该字母;否则输出No letter.。

    样例输入
    3
    A Right
    B Left
    Q Left


    样例输出
    S
    V
    No letter.

    import java.util.*;
    public class Test {
    	public static void main(String[] args) {
    		String[] a = {
    				"-","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","-"
    		};
    		Scanner sc = new Scanner(System.in);
    		int m = sc.nextInt();
    		String[] s = new String[m];
    		for(int i=0;i<m;i++) {
    			String c, r;
    			c = sc.next();
    			r = sc.next();
    			int aa=0;
    			for(int j=0;j<30;j++){
    				if(a[j].equals(c)){
    					aa = j;
    					break;
    				}
    			}
    			aa = r.equals("Left")?aa-1:aa+1;
    			s[i] = a[aa].equals("-")?"No letter.":a[aa];
    		}
    		for(int i=0;i<m;i++) {
    			System.out.println(s[i]);
    		}
    	}
    }
    

      

  • 相关阅读:
    SQLAlchemy
    Redis
    Django框架详解
    nginx负载均衡(反向代理)
    Python 字典 fromkeys()方法
    docker容器的使用
    keepalived原理
    学习区块链必读的6本书
    MATLAB基础入门笔记
    思念是一种美丽的孤独
  • 原文地址:https://www.cnblogs.com/duanyingkui/p/8342424.html
Copyright © 2011-2022 走看看