We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C++ solution
I hope this gives you an idea and learn how this one works
#include<bits/stdc++.h>usingnamespacestd;stringltrim(conststring&);stringrtrim(conststring&);vector<string>split(conststring&);intmain(){stringn_temp;getline(cin,n_temp);intn=stoi(ltrim(rtrim(n_temp)));stringarr_temp_temp;getline(cin,arr_temp_temp);vector<string>arr_temp=split(rtrim(arr_temp_temp));vector<int>arr(n);for(inti=0;i<n;i++){//n = size of arrayintarr_item=stoi(arr_temp[i]);//convert string to int(?)arr_temp[i]=arr[n-i-1];//swap elementarr[n-i-1]=arr_item;//swap element}for(inti=0;i<n;i++){cout<<arr[i]<<" ";//prints the reversed}return0;}stringltrim(conststring&str){strings(str);s.erase(s.begin(),find_if(s.begin(),s.end(),not1(ptr_fun<int,int>(isspace))));returns;}stringrtrim(conststring&str){strings(str);s.erase(find_if(s.rbegin(),s.rend(),not1(ptr_fun<int,int>(isspace))).base(),s.end());returns;}vector<string>split(conststring&str){vector<string>tokens;string::size_typestart=0;string::size_typeend=0;while((end=str.find(" ",start))!=string::npos){tokens.push_back(str.substr(start,end-start));start=end+1;}tokens.push_back(str.substr(start));returntokens;}
Day 7: Arrays
You are viewing a single comment's thread. Return to all comments →
C++ solution I hope this gives you an idea and learn how this one works