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]);
		}
	}
}

  

 

posted @ 2018-01-24 16:45  谨言&慎独_yk  阅读(429)  评论(1编辑  收藏  举报