Throwing cards away UVa10935

水题,输出的 remaining 巧妙地打错了导致wa。

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
#include <iostream>
#include <vector>
using namespace std;
vector<int> deck;
int main()
{
int n;
while (cin >> n && n)
{
deck.clear();
for (int i = 0; i <= n; i++)
deck.push_back(i);
int tot = 1, kase = 0;
cout << "Discarded cards:";
while (tot < n)
{
if (kase++)
cout << ",";
cout << ' ' << deck[tot];
tot++;
deck.push_back(deck[tot++]);
n++;
}
cout << endl << "Remaining card: " << deck[tot] << endl;
}
return 0;
}