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 |
啥状况 , 那位大哥帮忙解决下,一直WA// 08软件 谷恺 // #1028 #include <stdio.h> #include <iostream> #include <string.h> #define MAX_CH 70 #define MAX_URL 100 using namespace std; typedef struct { char url[MAX_URL][MAX_CH]; int top; }seqstack; void del(seqstack * sta) { sta->top--; } int bak(seqstack * bac, seqstack * fwd, char cur[]) { if (bac->top == -1) { return 0; } else { // 把cur存到栈fwd fwd->top++; strcpy(fwd->url[fwd->top], cur); strcpy(cur, bac->url[bac->top]); del(bac); return 1; } return 1; } int fowd(seqstack * bac, seqstack * fwd, char cur[]) { if (fwd->top == -1) { return 0; } else { // 把cur存到栈bac bac->top++; strcpy(bac->url[bac->top], cur); strcpy(cur, fwd->url[fwd->top]); del(fwd); return 1; } return 1; } void init(seqstack * stk) { stk->top = -1; } int main() { seqstack back; seqstack fwd; char cur[MAX_CH] = {"http://www.acm.org/"}; char temp[MAX_CH] = {0}; char res[200][MAX_CH]; int cnt = 0; init(&back); init(&fwd); while ( (cin >> temp) && strcmp(temp, "QUIT") != 0) { char url[MAX_CH]; if (strcmp(temp, "VISIT")==0) // VISIT PAGE { back.top++; strcpy(back.url[back.top], cur); init(&fwd); cin >> cur; strcpy(res[cnt], cur); cout << res[cnt] << endl; } else { if (strcmp(temp, "FORWARD")==0) { int t; t = fowd(&back, &fwd, cur); // function forward if(t == 0) { strcpy(res[cnt], "Ignored"); cout << res[cnt] << endl; } else { strcpy(res[cnt], cur); cout << res[cnt] << endl; } } else { if (strcmp(temp, "BACK")==0) { int t; t = bak(&back, &fwd, cur);// function back if(t == 0) { strcpy(res[cnt], "Ignored"); cout << res[cnt] << endl; } else { strcpy(res[cnt], cur); cout << res[cnt] << endl; } } } } cnt++; } /*for (int i = 0; i < cnt; i++) { cout << res[i] << endl; }*/ return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator