|
|
вернуться в форумI've got a WA on Test#6.Please look at my code... Послано PoiNT 11 авг 2005 15:10 #include <iostream> using namespace std; //------------------------------------------------------------------- class TStack { public: TStack* Insert(int Value); TStack* Add(int x); TStack * Next; int Value; TStack(); }; bool Find(int Value, TStack *ptr); void deleteStack(TStack *ptr); //------------------------------------------------------------------- int main() { TStack * Head = new TStack(); TStack * ptr; ptr = Head; int N; cin >> N; for(int i=0;i<N;i++) { TStack * HeadArray = new TStack(); TStack * ptrArray = HeadArray; int Ai; cin >> Ai; while(Ai != 0) { ptrArray = ptrArray->Add(Ai); cin >> Ai; } ptr = Head; bool flag = true; while(flag) { if(i == 0) { ptr->Add(i+1); flag = false; } else { bool change = true; while(ptr->Next != NULL && change) { ptrArray = HeadArray; if(Find(ptr->Next->Value,ptrArray)) { ptr->Insert(i+1); change = false; } else { ptr = ptr->Next; } } if(change) { ptr->Add(i+1); } flag = false; } } deleteStack(HeadArray); } ptr = Head->Next; while(ptr != NULL) { cout << ptr->Value << " "; ptr = ptr->Next; } deleteStack(Head); cin >> N; return 0; }; //------------------------------------------------------------------- bool Find(int Value, TStack *ptr) { bool result = false; while(ptr != NULL && !result) { if(ptr->Value == Value) result = true; else { ptr = ptr->Next; } } return result; } //------------------------------------------------------------------- TStack::TStack() { Next = NULL; Value = 0; } //------------------------------------------------------------------- TStack* TStack::Add(int x) { TStack * ptrValue = new TStack(); ptrValue->Value = x; Next = ptrValue; return ptrValue; } //------------------------------------------------------------------- TStack* TStack::Insert(int Value) { TStack *ptrValue = new TStack(); ptrValue->Value = Value; ptrValue->Next = Next; Next = ptrValue; return ptrValue; } //------------------------------------------------------------------- void deleteStack(TStack *ptr) { while(ptr != NULL) { TStack *ptrBuff = ptr; ptr = ptr->Next; delete ptrBuff; } return; } Re: I've got a WA on Test#6.Please look at my code... Use TopSort in graph. |
|
|