Jvsierra

10082 - WERTYU UVA Online Judge

Aug 4th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #define LIM 10001
  6.  
  7. int buscaVet(char c, char vet[]);
  8.  
  9. int main()
  10. {
  11.     int i, a;
  12.     char alf1[] = "qwertyuiop[]";
  13.     char alf2[] = "asdfghjkl;'";
  14.     char alf3[] = "zxcvbnm,./";
  15.     char str[LIM], carac;
  16.    
  17.     fflush(stdin);
  18.     gets(str);
  19.    
  20.     while(strcmp(str, "") != 0)
  21.     {
  22.         for(i = 0; str[i] != '\0'; i++)
  23.         {
  24.                 a = buscaVet(str[i], alf1);
  25.                
  26.                 if(a == -1)
  27.                 {
  28.                     a = buscaVet(str[i], alf2);
  29.                    
  30.                     if(a == -1)
  31.                     {
  32.                         a = buscaVet(str[i], alf3);
  33.                        
  34.                         if(a != -1)
  35.                             carac = alf3[a - 1];
  36.                     }
  37.                     else
  38.                         carac = alf2[a - 1];
  39.                 }
  40.                 else
  41.                     carac = alf1[a - 1];
  42.                
  43.                 if(a != -1)
  44.                     str[i] = toupper(carac);
  45.         }
  46.        
  47.         printf("%s\n", str);
  48.        
  49.         fflush(stdin);
  50.         gets(str);
  51.     }
  52.    
  53.     return 0;
  54. }
  55.  
  56. int buscaVet(char c, char vet[])
  57. {
  58.     int pos = 0;
  59.    
  60.     while(pos < strlen(vet) && vet[pos] != tolower(c))
  61.         pos++;
  62.        
  63.     if(pos == strlen(vet))
  64.         pos = -1;
  65.        
  66.     return pos;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment