Codeforces Round #271 (Div. 2) A. Keyboard

Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:

qwertyuiop
asdfghjkl;
zxcvbnm,./

Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button
(left or right, as specified in input).

We have a sequence of characters he has typed and we want to find the original message.

Input

First line of the input contains one letter describing direction of shifting (‘L‘ or ‘R‘ respectively
for left or right).

Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole‘s
keyboard. It doesn‘t contain spaces as there is no space on Mole‘s keyboard.

It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.

Output

Print a line that contains the original message.

Sample test(s)

input

R
s;;upimrrfod;pbr

output

allyouneedislove

题意:求原串。

思路:模拟。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char str[123456];
char dir[42];

int main() {
	string w[3];
	w[0] = "qwertyuiop";
	w[1] = "asdfghjkl;";
	w[2] = "zxcvbnm,./";
	scanf("%s%s", dir, str);
	for (int i = 0; str[i]; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < w[j].length(); k++) {
				if (w[j][k] == str[i]) {
					if (dir[0] == 'L')
						printf("%c", w[j][k+1]);
					else printf("%c", w[j][k-1]);
				}
			}
		}
	}
	printf("\n");
	return 0;
}
时间: 2024-10-10 05:02:20

Codeforces Round #271 (Div. 2) A. Keyboard的相关文章

Codeforces Round #271 (Div. 2) D. Flowers (递推)

题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类有多少. 递推,dp[i]表示长度为i的种类有多少.当i < k的时候 dp[i] = 1 , 当i == k的时候 dp[i] = 2 ,  否则 dp[i] = dp[i - 1] + dp[i - k] . 1 #include <bits/stdc++.h> 2 using name

Codeforces Round #271 (Div. 2) F.Ant colony(线段树 + 统计区间内某数的个数)

F. Ant colony Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He c

Codeforces Round #271 (Div. 2) D.Flowers DP

D. Flowers We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several

Codeforces Round #271 (Div. 2)

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are label

Codeforces Round #271 (Div. 2)D(递推,前缀和)

很简单的递推题.d[n]=d[n-1]+d[n-k] 注意每次输入a和b时,如果每次都累加,就做了很多重复性工作,会超时. 所以用预处理前缀和来解决重复累加问题. 最后一个细节坑了我多次: printf("%I64d\n",(s[b]-s[a-1]+mod)%mod); 这句话中加mod万万不能少,因为理论上s[b]-s[a-1]肯定大于0,但是由于两个都是模1000000007以后的结果,那么就不一定了,当s[b]-s[a-1]<0时结果是负的,不是题意中应该输出的结果,所以一

Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, s

(补题解)Codeforces Round #271 (Div. 2)

前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 1 #include<string.h> 2 #include<math.h> 3 #include<algorithm> 4 #include<stdio.h> 5 #include<math.h> 6 #include<string> 7 #include<i

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i