2018年5月12日 星期六

itsa [C_MM072-易]心得報數

#include <iostream>
using namespace std;

int main()
{
int n,N,K,P,a,c,j,tmp;
int *num;
cin >> n;
for (int i = 0;i < n; i++)
{
j = 0;
    c = 0;
cin >> N;
cin >> K;
tmp = N;
num = new int[N];
for (int a = 0;a < N; a++)
{
num[a] = 1;
}
for (int j = 0;j <= N; j++)
{
if (j == N)
{
j = 0;
}
if (num[j] == 0)
{

}
else if (num[j] == 1)
c++;
if (c == K)
{
num[j] = 0;
c = 0;
tmp--;
}
if (num[j] == 1 && tmp == 1)
    {
    P = j + 1;
    break;
        }
}
cout << P << endl;
delete []num;
}
return 0;
}

沒有留言:

張貼留言