將輸入字串中的字對應到鍵盤,輸出它左邊一格的字

[心得]

1.右斜線(\)和單引號(')在判斷時前面記得再加一個右斜線

2.記得加終止條件EOF

 

#include <stdio.h>

int main()
{
    char input;
   
    while((input=getchar())!=EOF)
    {
        switch(input)
        {
            case '1': {printf("`"); break;}
            case '2': {printf("1"); break;}
            case '3': {printf("2"); break;}
            case '4': {printf("3"); break;}
            case '5': {printf("4"); break;}
            case '6': {printf("5"); break;}
            case '7': {printf("6"); break;}
            case '8': {printf("7"); break;}
            case '9': {printf("8"); break;}
            case '0': {printf("9"); break;}
            case '-': {printf("0"); break;}
            case '=': {printf("-"); break;}
           
            case 'W': {printf("Q"); break;}
            case 'E': {printf("W"); break;}
            case 'R': {printf("E"); break;}
            case 'T': {printf("R"); break;}
            case 'Y': {printf("T"); break;}
            case 'U': {printf("Y"); break;}
            case 'I': {printf("U"); break;}
            case 'O': {printf("I"); break;}
            case 'P': {printf("O"); break;}
            case '[': {printf("P"); break;}
            case ']': {printf("["); break;}
            case '\\': {printf("]"); break;}
           
            case 'S': {printf("A"); break;}
            case 'D': {printf("S"); break;}
            case 'F': {printf("D"); break;}
            case 'G': {printf("F"); break;}
            case 'H': {printf("G"); break;}
            case 'J': {printf("H"); break;}
            case 'K': {printf("J"); break;}
            case 'L': {printf("K"); break;}
            case ';': {printf("L"); break;}
            case '\'': {printf(";"); break;}
           
            case 'X': {printf("Z"); break;}
            case 'C': {printf("X"); break;}
            case 'V': {printf("C"); break;}
            case 'B': {printf("V"); break;}
            case 'N': {printf("B"); break;}
            case 'M': {printf("N"); break;}
            case ',': {printf("M"); break;}
            case '.': {printf(","); break;}
            case '/': {printf("."); break;}
            case ' ': {printf(" "); break;}
            case '\n': {printf("\n"); break;}
           
            default: break;
        }                 
    }
   
    return 0;
}

創作者介紹
創作者 RingsACM 的頭像
RingsACM

Ring's ACM

RingsACM 發表在 痞客邦 留言(0) 人氣()