Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单题,附代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator