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;
}
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;
}
why you have used "\" this two times?
ReplyDeletein C/C++ '\' is considered as a keyword. So, to make it variable it needs to use one more \ (backslash)
DeleteHope you will get your answer here... :)
ReplyDeletehttps://www.quora.com/How-can-you-print-a-backslash-using-any-of-the-printf-family-of-functions