-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1244.cpp
More file actions
80 lines (77 loc) · 1.09 KB
/
1244.cpp
File metadata and controls
80 lines (77 loc) · 1.09 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 1244. 스위치 켜고 끄기
// 2019.05.14
#include<iostream>
#include<algorithm>
using namespace std;
int switches[101];
// 꺼져있는건 키고 켜져있는건 끔
int OnOff(int n)
{
if (n == 0)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> switches[i];
}
int k;
cin >> k;
for (int i = 0; i < k; i++)
{
int flag, num;
cin >> flag >> num;
if (flag == 1) // 남학생
{
int mul = num;
while (num <= n)
{
switches[num] = OnOff(switches[num]);
num += mul;
}
}
else // 여학생
{
int left = num + 1;
int right = num - 1;
switches[num] = OnOff(switches[num]);
while (1)
{
if (left > n || right <= 0)
{
break;
}
if (switches[left] == switches[right])
{
switches[left] = OnOff(switches[left]);
switches[right] = OnOff(switches[right]);
}
else
{
break;
}
left++;
right--;
}
}
}
for (int i = 1; i <= n; i++)
{
cout << switches[i] << " ";
if (i % 20 == 0)
{
cout << endl;
}
}
cout << endl;
return 0;
}