some kind of Josephus problem

TASK 1: BUSINESS TASKS
A busy businessman has a number of equally important tasks which he must accomplish. To decide which of the tasks to perform first, he performs the following operation.

He writes down all his tasks in the form of a circular list, so the first task is adjacent to the last task. He then thinks of a positive number. This number is the random seed, which he calls n. Starting with the first task, he moves clockwise (from element 1 in the list to element 2 in the list and so on), counting from 1 to n. When his count reaches n, he removes that task from the list and starts counting from the next available task. He repeats this procedure until one task remains. It is this last task that he chooses to execute.

Input: BTASK.IN
Your program must read from standard input the following data. The first line contains 2 integer n and r separated by a space character. n is the number of tasks where 2 <= n <= 50. r is the random number where 1 <= r <= 10000. The next n-th lines are the name of the tasks.

Output: BTASK.OUT
The output consist of a single string of the task the businessman had chosen to accomplish

Example 0 Input
4 2
a
b
c
d
Example 0 Output: "a"

Start counting from "a". So "a"=1, "b"=2. Remove "b", so the list is now {a,c,d}.
Continue from "c". So "c"=1, "d"=2. Remove "d", so the list is now {a,c}.
Continue from "a". So "a"=1, "c"=2. Remove "c", and the only task left is "a".

Example 1 Input
5 3
alpha
beta
gamma
delta
epsilon
Example 1 Output: "delta"

Example 2 Input
26 17
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Example 2 Output: "n"



The question is like this.Below is my code.However,it does not run.Can sb help?


#include<iostream>
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
char data[1.txt];
int length;
}*PSeqList;

void Delete(PSeqList p , int x)
{
int j;
if( ! p)
{
printf("no element!\n");
}
if( x<-1 | | i > p->length )
{
printf£¨"no element!\n"£©;
}

for( j=x; j< p->length; j++)
{
p->data[ j-1]=p->data [j] ;
p->length--;
}
}

int Task(PSeqList p, int n ,int r)
{
int s , i ;
if( !p->length )
{
printf("no element!\n");
return 0;
}
s=n-1;
printf("type out last element:\n");
for( i=p->length; i>=0 ; i++)
{
s=( s+ r -1) %i;
Delete(p,s+1);
if(p->length==1)
printf("%c\t",p->data[0]);
}
return 1;
}
Topic archived. No new replies allowed.