UVa10082 WERTYU

10082 WERTYU
A common typing error is to place the hands on the keyboard one row to the right of the correct position. So ‘Q’ is typed as ‘W’ and ‘J’ is typed
as ‘K’ and so on. You are to decode a message typed in this manner.
Input
Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above[except back-quote (` )]. Keys labelled with words [Tab, BackSp,Control, etc.] are not represented in the input.
Output
You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’keyboard shown above. Spaces in the input should be echoed in the output.
Sample Input
O S, GOMR YPFSU/
Sample Output
I AM FINE TODAY.

这道题貌似在tyvj上见过,当时认为要用一连串的if或者是swich,看了白书之后才发现利用常亮数组可以很好地解决这道题。

一个需要注意的地方就是’\’需要用转移字符’\\’来表示。

废话不多说了,直接上代码:

#include <stdio.h>
char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;‘ZXCVBNM,./";/*pay attenrion to \\ */
int main()
{
  int i, c;
  while((c = getchar()) != EOF)
  {
    for(i = 1; s[i] && s[i] != c; i++);
    if(s[i]) putchar(s[i-1]);
    else putchar(c);
  }
  return 0;
}

话说Dev-C++的Astyle真是恐怖……好好的代码顿时没有美感了,强迫症的我还是仔细的修改了一下。

putchar()输出单个字符是相当方便的,个人认为手打scanf()的速度比putchar()慢多了(可能是我手速慢的原因)。

这个代码里在数组里寻找单个元素的写法也是值得学习的。

时间: 2024-11-14 02:54:05

UVa10082 WERTYU的相关文章

POJ2538 ZOJ1884 UVA10082 WERTYU

问题链接:POJ2538 ZOJ1884 UVA10082 WERTYU.入门练习级题,用C语言编写程序. 这个问题是有关输入输出流处理和字符转换问题.将键盘上的字符放在数组中备查可以省去许多程序逻辑. 做了一个函数convert()封装字符转换功能,可以简化主函数的逻辑. AC的C语言程序如下: /* POJ2538 ZOJ1884 UVA10082 WERTYU */ #include <stdio.h> char s[]="`1234567890-=QWERTYUIOP[]\\

Uva10082 WERTYU -S.B.S.

A common typing error is to place the hands on the keyboard one row to the right of the correct position. So ‘Q’ is typed as ‘W’ and ‘J’ is typed as ‘K’ and so on. You are to decode a message typed in this manner. Input Input consists of several line

C语言编程常见技巧(问题???)

本文章根据<算法竞赛入门经典(第二版)>一书整理... 第一章 程序设计入门 printf 语句控制输出小数位数或总长度 printf("%.3f\n",8.0/5.0) //小数位数为3. printf("%.*f\n",3,8.0/5.0) //用3来代替* ,用来动态指定小数位数 printf("%3d",xxx) //指定输出宽度为3 printf("%-3d",xxx) //左对齐,邮编填补空格 prin

WERTYU(WERTYU, UVa10082)

把手放在键盘上时,稍不注意就会往右错一 位.这样,输入Q会变成输入W,输入J会变成输 入K等.键盘如图所示. 输入一个错位后敲出的字符串(所有字母均大写),输出打字员本来想打出的句子.输入保 证合法,即一定是错位之后的字符串.例如输入中不会出现大写字母A. 样例输入: O S, GOMR YPFSU/ 样例输出: I AM FINE TODAY. 分析:每输入一个字符,都可以直接输出一个字符,因此getchar是输入的理 想方法..问题在于:如何进行这样输入输出变换呢?一种方法是使用if语句或者

poj 2538 WERTYU

WERTYU Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8492   Accepted: 4063 Description A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and

UVa10082

10082 WERTYUA common typing error is to place the hands onthe keyboard one row to the right of the correctposition. So ‘Q’ is typed as ‘W’ and ‘J’ is typedas ‘K’ and so on. You are to decode a messagetyped in this manner.InputInput consists of severa

FZU 1343 WERTYU --- 水题

FZU 1343 题目大意:手放在键盘上时,稍不注意就会往右错一位.这样Q就会输入成W,输入J就会变成K 给定一串大写敲错后输入,输出正确的输入(输入保证合法,如输入中不会出现Q,A,Z): 解题思路:将字符按键盘顺序存在一个数组中,然后找到每个字符在数组中的位置,输出它的前一个字符,若未找到则输出原字符 /* FZU 1343 WERTYU --- 水题 */ #include <cstdio> char s[] = "`1234567890-=QWERTYUIOP[]\\ASDF

算法竞赛入门经典 5.1.1 WERTYU 5.1.2 Tex括号

5.1.1  WERTYU 把手放在键盘上时,稍不注意就会往右错一位. 这样的话,Q会变成W,J会变成K等. 输入一个错位敲出的字符串,输出打字员本来想打出的句子. 样例输入:O S,GOMR YPFSU/ 样例输出:I AMFINE TODAY. #include <stdio.h> #include <stdlib.h> char *s = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; int mai

POJ 之 WERTYU

WERTYU Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8371   Accepted: 4007 Description A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and