10082 - WERTYU

本文介绍了一种键盘错位输入解码算法,通过将输入的每个字符替换为QWERTY键盘上其左侧的字符来还原原本的文本。提供了两种实现方式,一种使用连续查找并替换的方法,另一种虽存在bug但作为后续改进的基础。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem C: WERTYU

A common typing error is to place the hands on the keyboard one rowto 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 typedin this manner.

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.] arenot represented in the input.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/

Output for Sample Input

I AM FINE TODAY.

#include <stdio.h>
#include <stdlib.h>
char c[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
int main()
{
    int i,a;
        while ((a=getchar())!=EOF)
        {
            for (i=0;c[i]&&c[i]!=a;i++);
                if (c[i]) putchar(c[i-1]);
                else putchar(a);
        }
    return 0;
}
实在是没想到别的方法
还有一个和书本上不同的做法,但是有bug
也记录下来,以后看能解决不
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a;
    int i,k;
    char c[]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
    while ((a=getchar())!=EOF)
        {
            for (k=0;k<=46;k++)

                   if (c[k]==a)

            {printf("%c\n",c[k-1]);
            break;
            }
        }
    return 0;
}
////有bug


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值