zoukankan      html  css  js  c++  java
  • 字符串~键盘错位

    
    

    
    
     1 //------------C_Style-----------------
     2 
     3 #include<stdio.h>
     4 
     5 void main()
     6 {
     7     char *str = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
     8     int c;
     9     printf("Enter a string(Ctr+Z to end):\n");
    10     while((c = getchar()) != EOF)
    11     {
    12         for(int ix = 1; str[ix] && str[ix] != c; ++ix);
    13             if(str[ix])
    14                 putchar(str[ix-1]);
    15             else
    16                 putchar(c);
    17     }
    18 }
     1 //------------C++_Style-----------------
     2 
     3 #include<iostream>
     4 #include<string>
     5 using namespace std;
     6 
     7 string str = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
     8 void main()
     9 {
    10     string s;
    11     cout << "Enter a string(Ctr+Z to end):" << endl;
    12     getline(cin, s);
    13     for(string::size_type ix = 0; ix != s.size(); ++ix)
    14     {
    15         string::size_type index = 1;
    16         for(; index != str.size() && str[index] != s[ix]; ++index);
    17         if(index != str.size())
    18             s[ix] = str[index-1];
    19     }
    20     cout << s << endl;
    21 }
    /*
    比较以上两个代码,对于这类低级的题目C字符串风格char给适合写……
    另外,对于小规模的题目,可以使用本题的常量数组,把所有可能情况都列出来,与问题相比较处理,这样更简洁……
    */
  • 相关阅读:
    2020 HDU校赛 Problem J
    2020 HDU校赛 Problem I
    2020年HDU校赛 Problem A
    HDU 2553 N皇后 (dfs+回溯)
    D
    #6177. 「美团 CodeM 初赛 Round B」送外卖2(floyed + 三进制枚举 )
    E
    B
    大数加法模板(可能有问题,目前没发现)
    H
  • 原文地址:https://www.cnblogs.com/sanghai/p/2759358.html
Copyright © 2011-2022 走看看