Monday, August 20, 2018

REVERSE STRING

  • Problem Description

    "If an Integer N, write a program to reverse the given number.
    Input

    The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
    Output

    Display the reverse of the given number N.
    Constraints

    1 <= T<= 1000
    1 <= N <= 100000
    "
  • CODING ARENA::
  • #include <stdio.h>
    #include<string.h>
    void reverse(char str1[], int index, int size)
    {
        char temp;
        temp = str1[index];
        str1[index] = str1[size - index];
        str1[size - index] = temp;
        if (index == size / 2)
        {
            return;
        }
        reverse(str1, index + 1, size);
    }
    int main()
    {int n;
     scanf("%d",&n);
     while(n--)
     {
       char a[100];
       scanf("%s",a);
       reverse(a,0,strlen(a)-1);
       printf("%s\n",a);
     }
     return 0;}
  • Test Case 1

    Input (stdin)
    3 
    
    12345
    
    31203
    
    2123
    
    
    Expected Output
    54321
    
    30213
    
    3212
  • Test Case 2

    Input (stdin)
    2
    
    78657
    
    100034
    
    
    Expected Output
    75687
    
    430001

No comments:

Post a Comment