Arrays Introduction | HackerRank
Arrays Introduction | HackerRank
How to access and use arrays. Print the array in the reverse order.
www.hackerrank.com
Goal
Print the N integers of the array in the reverse order, space-separated on a single line.
Solution
1. Create array with N size.
2. Save N integers into array.
3. Print reverse array with space
// Arrays Introduction
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin >> n;
int a[n];
int tmp;
int i = 0;
while (cin >> tmp)
{
a[i] = tmp;
i++;
}
for(int index = n - 1; index >=0 ; index--){
if(index !=0){
cout << a[index] << " ";
}
else{
cout << a[index] << endl;
}
}
return 0;
}
'software Engineering > (C++)HackerRank' 카테고리의 다른 글
[C++] HackerRank - Variable Sized Arrays (0) | 2023.02.10 |
---|---|
[C++] HackerRank - Pointer (0) | 2023.02.08 |
[C++] HackerRank - Functions (0) | 2023.02.04 |
[C++] HackerRank - For Loop (0) | 2023.01.24 |
[C++] HackerRank - Conditional Statements (0) | 2023.01.24 |