Sort by

recency

|

2031 Discussions

|

  • + 0 comments
    C# code
    
    class Solution
    {
        public static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
    
            var rec = Console.ReadLine();
            if(rec != null)
            {
                List<int> arr = rec.TrimEnd().Split(' ').Reverse().ToList().Select(arrTemp => Convert.ToInt32(arrTemp)).ToList();
                
    //if you dont want to use foreach can use string.join ( string outPut = String.Join(" ", arr); )
            
                foreach(var data in arr)
                {
                    Console.Write(data+" ");
                }
            }
        }
    }
    
  • + 0 comments

    For JAVA

    int[] a=new int[n];

        for(int i=n-1;i>=0;i--){
            a[i]=arr.get(i);  
            System.out.print(a[i]+" ");
        }
    
  • + 0 comments

    Python3:

    if __name__ == '__main__':
        n = int(input().strip())
    
        arr = list(map(int, input().rstrip().split()))
        print(*reversed(arr), sep=' ')
    
  • + 0 comments

    Python Code: simply use * to unpack the list when printing.

    arr = list(map(int, input().rstrip().split()))

    print(*list(reversed(arr)))

  • + 0 comments

    Python code-

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    if __name__ == '__main__':
        n = int(input().strip())
    
        arr = list(map(int, input().rstrip().split()))
    l= len(arr)
    if l in range(1,1001):
        for i in range(l-1, -1, -1):
            if arr[i] in range(1,10001):
                print (arr[i], end=' ')