SW Expert Academy
(SWEA c++)1230. [S/W 문제해결 기본] 8일차 - 암호문3
naeunchan
2020. 10. 13. 10:54
728x90
반응형
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
암호문2에서 'A' 명령어가 추가된 문제.
list를 이용하여 'A' 명령어까지 구현한다.
맨 뒤에 y개만큼 숫자를 더하면 되니
list의 push_back()함수를 이용하여 풀면 된다.
#include <iostream>
#include <list>
using namespace std;
int main(void)
{
for(int t = 1; t <= 10; t++)
{
int n, x, y, s;
char c;
list<int> lt;
auto itr = lt.begin();
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> x;
lt.push_back(x);
}
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> c;
if(c == 'I')
{
list<int> tmp;
itr = lt.begin();
cin >> x >> y;
for(int j = 0; j < x; j++)
itr++;
for(int j = 0; j < y; j++)
{
cin >> s;
tmp.push_back(s);
}
lt.splice(itr, tmp);
}
else if(c == 'D')
{
itr = lt.begin();
cin >> x >> y;
for(int j = 0; j < x; j++)
itr++;
for(int j = 0; j < y; j++)
itr = lt.erase(itr);
}
else if(c == 'A')
{
cin >> y;
for(int j = 0; j < y; j++)
{
cin >> s;
lt.push_back(s);
}
}
}
itr = lt.begin();
cout << "#" << t << " ";
for(int i = 0; i < 10; i++, itr++)
cout << *itr << " ";
cout << endl;
}
return 0;
}
728x90
반응형