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 <iostream> #include <stdio.h> #include <string.h> using namespace std; void print3(int n){ if(n < 10) printf(" "); else if(n < 100) printf(" "); printf("%d ", n); } int main() { char name[20]; while(scanf("%s", name) > 0){ int remain[25]; int cs = 0; while(1){ int temp; scanf("%d", &temp); if(temp == -1) break; remain[cs] = temp; cs++; } int knock[25]; int sg = 10; int dqcs = 0; for(int i = 0; i < cs; i++){ knock[i] = sg - remain[i]; sg = remain[i]; dqcs ++; if(sg == 0 || dqcs == 2){ sg = 10; dqcs = 0; } } int start[12], last[12]; int place = 0, frame = 0; while(place < cs && frame < 10){ start[frame] = place; if(knock[place] == 10){ last[frame] = 1; frame++; place++; } else if(place == cs-1){ last[frame] = 1; frame++; break; } else{ last[frame] = 2; frame++; place+=2; } } int len = strlen(name); printf("%s", name); for(int i = 0; i < 13-len; i++) printf(" "); int score[15]; for(int i = 0; i < frame; i++){ if(last[i] == 1 && knock[start[i]] == 10){//i==9时要考慮 printf("X"); if(i != 9) printf(" "); else{ if(start[i]+1<cs){ if(knock[start[i]+1] == 10) printf("X"); else if(knock[start[i]+1] == 0) printf("-"); else printf("%d", knock[start[i]+1]); } else printf(" "); if(start[i]+2<cs){ if(knock[start[i]+2] == 0) printf("-"); else if(knock[start[i]+1] + knock[start[i]+2] == 10) printf("/"); else if(knock[start[i]+2] == 10) printf("X"); else printf("%d", knock[start[i]+2]); } else printf(" "); printf(" "); } if(start[i]+2>=cs) score[i] = -1; else score[i] = 10 + knock[start[i]+1] + knock[start[i]+2]; } else if(last[i] == 1){ if(knock[start[i]] > 0){ printf("%d ", knock[start[i]]); } else{ printf("- "); } score[i] = -1; } else if(knock[start[i]] + knock[start[i]+1] == 10){ if(knock[start[i]] == 0) printf("-"); else printf("%d", knock[start[i]]); printf("/"); if(i != 9 || start[i]+2>=cs) printf(" "); else{ if(knock[start[i]+2] == 10) printf("X "); else if(knock[start[i]+2] == 0) printf("- "); else printf("%d ", knock[start[i]+2]); } if(start[i]+2 < cs) score[i] = 10 + knock[start[i]+2]; else score[i] = -1; } else{ if(knock[start[i]] > 0) printf("%d", knock[start[i]]); else printf("-"); if(knock[start[i]+1] > 0) printf("%d", knock[start[i]+1]); else printf("-"); printf(" "); score[i] = knock[start[i]] + knock[start[i]+1]; } } printf("\n "); int sc = 0; for(int i = 0; i < frame; i++){ if(score[i] == -1) break; sc += score[i]; print3(sc); } printf("\n\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator