#include<stdio.h>
//#include<conio.h>
//#include<string.h>
#include<string.h>
//#include<iostream.h>
int main()
{
    char al[28],b[104];
    int i=0;
    int t,k=0;
   // b[0]='A';
    scanf("%d\n",&t);
    while(t--)
    {
            // scanf("%s",b);
            gets(b);
            gets(al);
            //gets(al);
            //printf("%s",b);
            //puts(al);
            // scanf("%s",al);
        //    for(k=0;c1!='\n';k++)
        //    {
                                
                                    // scanf("%c",&c1);
          //                       //  b[k]=c1;
          //                         cin>>c1;
          //                         b[k]=c1;
         //  }
         //  printf("hello");
           // puts(b);
          // gets(b);
          // puts(b);
          k=strlen(b);
          //printf("%d",k);
             while(i<k)
             {
                            
                              
                              switch(b[i])
                              {
                                      case 'A':
                                           printf("%c",al[0]);
                                       //    printfal[0];
                                           break;
                                      
                                      case 'B':
                                           printf("%c",al[1]);
                                          // b[i]=al[1];;
                                           break;
                                           
                                       case 'C':
                                            printf("%c",al[2]);
                                        //   b[i]=al[2];
                                           break;
                                       
                                        case 'D':
                                             printf("%c",al[3]);
                                          // b[i]=al[3];
                                           break;
                                           
                                       case 'E':
                                            printf("%c",al[4]);
                                        //   b[i]=al[4];
                                           break;
                                           
                                        case 'F':
                                             printf("%c",al[5]);
                                          // b[i]=al[5];
                                           break;
                                           
                                         case 'G':
                                              printf("%c",al[6]);
                                        //   b[i]=al[6];
                                           break;
                                           
                                         case 'H':
                                              printf("%c",al[7]);
                                  //         b[i]=al[7];
                                           break;
                                           
                                          case 'I':
                                               printf("%c",al[8]);
                                         //  b[i]=al[8];
                                           break;
                                           
                                           
                                           case 'J':
                                                printf("%c",al[9]);
                                     //      b[i]=al[9];
                                           break;
                                           
                                           case 'K':
                                                printf("%c",al[10]);
                                      //     b[i]=al[10];
                                           break;
                                           
                                           case 'L':
                                                printf("%c",al[11]);
                                          // b[i]=al[11];
                                           break;
                                           
                                           case 'M':
                                                printf("%c",al[12]);
                                        //   b[i]=al[12];
                                           break;
                                           
                                           case 'N':
                                                printf("%c",al[13]);
                                        //   b[i]=al[13];
                                           break;
                                           
                                           case 'O':
                                                printf("%c",al[14]);
                                      //     b[i]=al[14];
                                           break;
                                           
                                           case 'P':
                                                printf("%c",al[15]);
                                        //   b[i]=al[15];
                                           break;
                                           
                                           case 'Q':
                                                printf("%c",al[16]);
                                        //   b[i]=al[16];
                                           break;
                                           
                                           case 'R':
                                                printf("%c",al[17]);
                                        //   b[i]=al[17];
                                           break;
                                          
                                           case 'S':
                                                printf("%c",al[18]);
                                        //   b[i]=al[18];
                                           break;
                                           
                                           case 'T':
                                                printf("%c",al[19]);
                                          // b[i]=al[19];
                                           break;
                                           
                                           case 'U':
                                                printf("%c",al[20]);
                                          // b[i]=al[20];
                                           break;
                                           
                                           case 'V':
                                                printf("%c",al[21]);
                                           //b[i]=al[21];
                                           break;
                                           
                                           case 'W':
                                                printf("%c",al[22]);
                                          // b[i]=al[22];
                                           break;
                                           
                                           case 'X':
                                                printf("%c",al[23]);
                                           //b[i]=al[23];
                                           break;
                                           
                                           case 'Y':
                                                printf("%c",al[24]);
                                        //   b[i]=al[24];
                                           break;
                                           
                                           case 'Z':
                                           printf("%c",al[25]);
                                           break;
                                           
                                           case ' ':
                                                printf("%c",b[i]);
                                                break;
                                          
                              } //switch
                              
                                i++;
             }   //while
             
            // for(i=0;i<k;i++)
           //  printf("%c",b[i]);
             i=0;
             printf("\n");
    }   //while
    
    //getch();
    return 0;
}   //main

in this code, when i give array of 26 or 27 then it doesn't work, but when i give 28 or higher it works properly as i want, why is this so ? although i am using only 26 character array. then why is it working when it's size is 28 ? why 2 more?

second question is that : when i don't give "\n" with the statement(number 12) (scanf("%d\n",&t), then it skip the gets() statement in the while loop , but when i give "\n"
then it works properly..please tell me because they are really good questions for me to have answers.

Edited 4 Years Ago by gourav1: n/a

>> in this code, when i give array of 26 or 27 then it doesn't work, but when i give 28 or higher it works properly as i want, why is this so ? although i am using only 26 character array. then why is it working when it's size is 28 ? why 2 more?

You don't mention what precisely doesn't work and when. Presumably there's a segmentation fault. I see a "gets" in there. I suggest you replace this with "fgets" and specify 26 as the length and stdin as the FILE*. Best guess is that you're overshooting the end of the array with the read in line 17.

http://www.cplusplus.com/reference/clibrary/cstdio/fgets/

Edited 4 Years Ago by VernonDozier: n/a

See this, this, and this.
Oh this, too.

damn awsome links. simply saying "superb info". and i am still not getting my second question....."second question is that : when i don't give "\n" with the statement(number 12) (scanf("%d\n",&t), then it skip the gets() statement in the while loop , but when i give "\n"
then it works properly..please tell me because they are really good questions for me to have answers."

Edited 4 Years Ago by gourav1: n/a

damn awsome links. simply saying "superb info". and i am still not getting my second question....."second question is that : when i don't give "\n" with the statement(number 12) (scanf("%d\n",&t), then it skip the gets() statement in the while loop , but when i give "\n"
then it works properly..please tell me because they are really good questions for me to have answers."

Whitespace in scanf()'s format string will tell scanf() to read and discard any and all whitespace. '\n' is the escape character for a new line, which is whitespace.

This article has been dead for over six months. Start a new discussion instead.