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 |
原创代码,16ms#include <stdio.h> #include <cstring> #include <string> #include <algorithm> using namespace std; #define MAX_N 5000 const char* pattern[3] = { "ACBCAB", "ACABC", "ACBABCB" }; string states[2][3]; string res; void init() { states[0][0] = "N"; states[0][1] = "O"; states[0][2] = "P"; int prev = 0, curr = 1; while (states[prev][0].length() < MAX_N) { for (int i = 0; i < 3; ++i) { states[curr][i] = ""; for (int j = 0; pattern[i][j]; ++j) { int idx = pattern[i][j] - 'A'; states[curr][i] += states[prev][idx]; } } prev = (prev + 1) % 2; curr = (curr + 1) % 2; } res = states[prev][0]; } int main() { init(); while (true) { int n; scanf_s("%d", &n); if (!n) break; while (n > MAX_N) printf("..."); for (int i = 0; i < n; ++i) { printf("%c", res[i]); } printf("\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