BOJ 문제풀이
백준 23175번 c++ 풀이
koreasunoo
2021. 10. 11. 00:16
SMALL
전략:
1. 특정한 숫자n이 n번 반복해서 나오므로 while문안에서 i에 n을 더해준다.
코드:
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m;
cin>>m;
vector<int> v(m);
for(int i= 0; i<m; ++i){
cin>>v[i];
}
int i = 0;
vector<int> result;
while(1){
if(i == m){
break;
}
result.emplace_back(v[i]);
i+= v[i];
}
for(int i = 0; i<result.size(); ++i){
cout<<result[i]<<" ";
}
cout<<"\n";
}
LIST