C언어/문제풀다 하나씩

문자 빼기 #include <vector> 써보기 arr.erase(arr.begin()+index);

mcdn 2020. 5. 13. 12:48
반응형

#include <iostream>
#include <vector>
using namespace std;



int main() {
	vector<char>arr = { 'B', 'H','A','I' };
	int n;
	cin >> n;
	for (int i = 0;i < 3;i++) {
		int len = arr.size();// 4
		int ind = n % len -1; // 5%4 == 1
		cout << arr[ind]<<" ";
		arr.erase(arr.begin() + ind);
	}
	cout << arr[0];
	
}
반응형