Sort by

recency

|

2032 Discussions

|

  • + 0 comments

    n = int(input().strip())

    arr = list(map(int, input().rstrip().split()))
    print(" ".join(map(str, arr[::-1])))
    
  • + 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)))