1069. Weibo forward lottery
Xiao-ming Pat a full mark, happy decided to launch a micro-Bo forward lottery, from the forwarded netizens in order every n individual sent a red envelope. Please write a program to help him determine the winning list.
Input Format:
Enter the first line to give three positive integers m (<= 1000), n, and S, respectively, the total number of forwards, the winning interval as determined by xiaoming, and the ordinal number of the first winner (numbering begins at 1). Then the M line, in order, gives the nickname of the Netizen who forwards the microblog (no more than 20 characters, a non-empty string that does not contain a space carriage return).
Note: It may be forwarded several times, but not many times. So if the user in the current winning position has already won the prize, skip him and take down one.
output Format:
Output the winning list in the order you entered, one for each nickname. If no one wins, the output is "Keep going ...". Enter Sample 1:
9 3 2
imgonnawin!
Pickme
pickmememeee
lookhere
imgonnawin!
Tryagainagain
tryagainagain
imgonnawin!
Tryagainagain
Output Sample 1:
Pickme
imgonnawin!
Tryagainagain
Enter Sample 2:
2 3 5
imgonnawin!
Pickme
Output Sample 2:
Keep going ...
There is only one case in which this question has been won: S>m. This problem to solve the core problem is to go to heavy, there is no good way, I was every input a winner on the check is not won, won the separate record of award, did not win the jump. The code is as follows:
#include <stdio.h> #include <string.h> struct name {char c[21];
NAME[1001];
int main (void) {int m,n,s;
int i,j,s1=0;
Char b[21];
scanf ("%d%d%d", &m,&n,&s);
if (s>m) {for (i=0;i<m;i++) gets (b);
printf ("Keep going...\n");
else {for (i=0;i<m;i++) {gets (b);
if (((++s1-s)%n==0&&s1>=s)) {for (j=0;j<i;j++) {
if (strcmp (name[j].c,b) ==0) {s1--;break;
} if (j==i) {strcpy (name[i].c,b);
printf ("%s\n", b);
return 0; }