Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么re呢, 是不是就是递归搜索阿

Posted by first at 2006-03-05 22:16:38 on Problem 2023
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
using namespace std;

string text[120];
char ce[120];
int choice[120][2];
vector <int> vchoice;
vector <int> vend;
vector <int> story;
string end[120];
string temp;
void find(int i)
{
	if (ce[i] == 'E')
	{
		if(end[i] == "HAPPY")
		{
			for(i = 0; i < story.size(); i ++)
			{  
				cout << text[story[i]] << endl;
			}
			return;
		}
	}
	else 
	{
		story.push_back(choice[i][0]);
		find(choice[i][0]);
		story.pop_back();
		story.push_back(choice[i][1]);
		find(choice[i][1]);
		story.pop_back();
	}
	return;
}

int  main()
{
	int n;
	cin >> n;
	int count =  1;
	while(n --)
	{
       int c, i, pos1, pos2;
	   vchoice.clear();
	   vend.clear();
	   story.clear();
	   cin >> c;
	   for(i = 1; i <= c; i ++)
	   {
		   cin >> ce[i];
		   getline(cin, text[i]);
		   pos1 = text[i].find_first_of('"', 0);
		   pos2 = text[i].find_last_of('"', text[i].length());
		   if(ce[i] == 'C')
		   {
			   choice[i][0] = text[i][text[i].length() - 1] - '0';
               choice[i][1] = text[i][text[i].length() - 3] - '0';
			   vchoice.push_back(i);
		   }
		   else
		   {
			   end[i] = text[i].substr(pos2 + 2, text[i].length() - pos2 - 2);
			   vend.push_back(i);
		   } 
		   text[i] = text[i].substr(pos1 + 1, pos2 - pos1 - 1);
	   }	
	   story.push_back(1);
	   cout << "STORY " << count ++ << endl;
	   find(1);  
	   
	}
	return 0;
   
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator