2.非0(有人),才算1個車廂
#include<iostream>
using namespace std;
int main()
{
int N, A, B, C, num, count;
int n[100] = { 0 };
cin >> N;
for (int i = 0; i < N; i++)
{
num = 0;
count = 0;
cin >> A >> B >> C;
for (int j = 0; j < C; j++)
n[j] = j + 1;
for (int j = 0; j < C - 1; j++)
{
count = 0;
if (j % 2 == 0)
{
while (count != B)
{
if (num < C - 1)
num++;
else
num = 0;
if (n[num] != 0)
count++;
}
n[num] = 0;
}
else
{
while (count != A)
{
if (num > 0)
num--;
else
num = C - 1;
if (n[num] != 0)
count++;
}
n[num] = 0;
}
}
for (int k = 0; k < C; k++)
{
if (n[k] != 0)
cout << n[k] << endl;
}
}
return 0;
}
沒有留言:
張貼留言