Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

简单题,附代码

Posted by KatrineYang at 2016-11-14 13:23:20 on Problem 1576
#include <stdio.h>
#include <string.h>
char square[2333];
char card[233][4];
int pNum, sNum, cNum;

int main(int argc, char **argv){
	while(1){
		scanf("%d%d%d",&pNum,&sNum,&cNum);
		if(!pNum) break;
		scanf("%s",square);
		for(int i = 1; i <= cNum; i++){
			scanf("%s",card[i]);
		}
		int pos[16] = {0};
		int win = 0;
		for(int i = 1; i <= cNum; i++){
			int curP = (i-1)%pNum+1;
			char col = card[i][0];
			int tarPos = -1;
			if(strlen(card[i]) == 1){
				for(int ps = pos[curP]+1; ps < sNum; ps++){
					if(square[ps-1] == col){
						tarPos = ps;
						break;
					}
				}
			}
			else{
				int colCnt = 0;
				for(int ps = pos[curP]+1; ps < sNum; ps++){
					if(square[ps-1] == col){
						colCnt++;
						if(colCnt == 2){
							tarPos = ps;
							break;
						}
					}
				}
			}
			if(tarPos == -1 || tarPos == sNum){
				printf("Player %d won after %d cards.\n", curP, i);
				win = 1;
				break;
			}
			else{
				pos[curP] = tarPos;
			}
		}
		if(!win){
			printf("No player won after %d cards.\n", cNum);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator