Wednesday, December 10, 2014

10082: WERTYU

For this problem, I created a character array, containing the keyboard characters in their original sequence. To translate a letter, i searched for the letter in the array and printed the letter that is one index before the index where the letter is located in. I had to detect spaces in the input as well. If the current letter is a space, print a space in the output as well.

#include "stdio.h"

int main() {
    char line[1000];
    int i, j;
    char orig[] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";

    while(gets(line)) {
        for(i = 0; line[i]; i += 1) {
            if(line[i] == ' ') {
                printf(" ");
                continue;
            }
            for(j = 0; orig[j]; j += 1) {
                if(line[i] == orig[j]) {
                    printf("%c", orig[j-1]);
                    break;
                }
            }
        }
        printf("\n");
    }

    return 0;
}

No comments:

Post a Comment