UVa Problem Solution: 10082 - WERTYU

本文介绍了一个简单的C++程序,该程序能够将特定的键盘错位输入转换为正确的字符输出。通过预先定义的错误键位与正确键位对应表,程序读取输入并输出纠正后的字符串。

The simplest problem ever since...

Code:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 10082 C++ "WERTYU" */
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. #include <vector>
  10. using namespace std;
  11. int ncharacters = 128;
  12. int const buffsize = 2048;     
  13.    
  14. int main(int argc, char *argv[])
  15. {
  16. #ifndef ONLINE_JUDGE
  17.   filebuf in, out;
  18.   cin.rdbuf(in.open((string(argv[0]) + ".in").c_str(), ios_base::in));
  19.   cout.rdbuf(out.open((string(argv[0]) + ".out").c_str(), ios_base::out));
  20. #endif
  21.   char table[ncharacters];
  22.   char x[] = "1234567890-=WERTYUIOP[]//SDFGHJKL;'XCVBNM,./ /n";
  23.   char y[] = "`1234567890-QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,. /n";
  24.   for (int i = 0; i < sizeof (x); ++i) {
  25.     table[x[i]] = y[i];
  26.   }
  27.   char typo[buffsize];
  28.   char type[buffsize];
  29.   while (true) {
  30.     cin.read(typo, buffsize);
  31.     int size = cin.gcount();
  32.     for (int i = 0; i < size; ++i) {
  33.       type[i] = table[typo[i]];
  34.     }
  35.     cout.write(type, size);
  36.     if (!cin) break;
  37.   }
  38.   return 0;
  39. }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值