https://programmers.co.kr/learn/courses/30/lessons/42586
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include<iostream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;
//[93, 30, 55], [1, 30, 5]
int main()
{
string str = "[95, 90, 99, 99, 80, 99], [1, 1, 1, 1, 1, 1]";// cin >> str;
int Len = str.length();
vector<int> progress, speed;
bool bIsProg = true;
for (int i = 0; i < Len; i++)
{
char buf[3]; int buf_Idx = 0;
while (!(str[i] == '[' || str[i] == ',' || str[i] == ' ' || str[i] == ']'))
{
if(isdigit(str[i]))
buf[buf_Idx++] = str[i++];
}
buf[buf_Idx] = '\0';
if (buf[0] != '\0')
{
if (bIsProg)
progress.push_back(atoi(buf));
else
speed.push_back(atoi(buf));
}
if (str[i] == ']')
bIsProg = false;
}
///////////////////////////////////////////////
/*사실 요부분이 찐!!*/
///////////////////////////////////////////////
while (!progress.empty())
{
int progSz = progress.size();
int popNum = 0;
while (progress.front() < 100)
{
for (int i = 0; i < progSz; i++)
progress[i] += speed[i];
}
for (int i = 0; i < progSz; i++)
{
if (progress[i] >= 100)
popNum++;
else
break;
}
cout << popNum << '\n';
progress.erase(progress.begin(), progress.begin() + popNum);
speed.erase(speed.begin(), speed.begin() + popNum);
}
/////////////////////////////////////////////////
}
|
cs |
" target="_blank" rel="noopener" data-mce-href="http://
'PS > 알고리즘' 카테고리의 다른 글
[백준 10814번] 정렬 - 나이순 정렬 (구조체/Pair 자료구조의 compare 함수!) (0) | 2021.06.30 |
---|---|
[프로그래머스 스택/큐] (level2) 2번 - 프린터 (0) | 2021.06.29 |
[프로그래머스] string 입력 참고 (0) | 2021.06.28 |
[백준 10828번] 스택 - 1차 스터디 A (0) | 2021.06.25 |
[백준 10942번] 팰린드롬 |오토마타|,|DP연습| (0) | 2021.02.24 |