Sunday, March 2, 2014

UVa 10082 - WERTYU solution

Problem link :  UVa 10082 - WERTYU

Solution : 


#include<bits/stdc++.h>
using namespace std;

char a[]={"`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"};

char f(char c)
{
    for(int i=0;i<47;i++)
    {
        if(a[i]==c) return a[i-1];
    }
    return c;
}

int main()
{
    char s[10005];
    while(gets(s))
    {
        int l=strlen(s);
        for(int i=0;i<l;i++) s[i]=f(s[i]);
        puts(s);
    }
    return 0;
}



3 comments:

  1. why you have used "\" this two times?

    ReplyDelete
    Replies
    1. in C/C++ '\' is considered as a keyword. So, to make it variable it needs to use one more \ (backslash)

      Delete
  2. Hope you will get your answer here... :)

    https://www.quora.com/How-can-you-print-a-backslash-using-any-of-the-printf-family-of-functions

    ReplyDelete