user-0 提问: 地铁次数问题

回复:
user: user-0
content: 大神你好,请问c++版本,如果拆成三个class, 分别是Track,Station, SubwaySystem.   class Track { 	public: 		Track(); 		Track(char input_node_1,char input_node_2); //起始点,终结点 		~Track(); 	private: 		bool visited;  		char node_1; 		char node_2; };  class Station { 	public: 		Station(); 		Station(char Current_Station_ID,int Starting_ID,int Current_Size);//  		~Station();  	private: 		char station_name; //车站名称 		int track_starting_ID;// 		int track_size;  };  class SubwaySystem { 	public: 		SubwaySystem(); 		...                     //Recursive function递归方程 		void SearchRoute(int Current_Station_ID);  		...                      //其他方程      	private: 		Track my_track[34]; 		Station my_station[12]; 		int count_routes; };    在SubwaySystem.cpp里面  #include "subway_system.h"  SubwaySystem::SubwaySystem() { 	//Initialize tracks 	my_track[0] = Track('a','b'); 	my_track[1] = Track('b','a'); 	my_track[2] = Track('b','c'); 	my_track[3] = Track('b','d'); 	my_track[4] = Track('b','e'); 	my_track[5] = Track('b','f'); 	my_track[6] = Track('c','b'); 	my_track[7] = Track('c','e'); 	my_track[8] = Track('d','b'); 	my_track[9] = Track('d','e'); 	my_track[10] = Track('e','b'); 	my_track[11] = Track('e','c'); 	my_track[12] = Track('e','d'); 	my_track[13] = Track('e','g'); 	my_track[14] = Track('e','h'); 	my_track[15] = Track('f','b'); 	my_track[16] = Track('f','h'); 	my_track[17] = Track('g','e'); 	my_track[18] = Track('g','k'); 	my_track[19] = Track('h','e'); 	my_track[20] = Track('h','f'); 	my_track[21] = Track('h','i'); 	my_track[22] = Track('h','j'); 	my_track[23] = Track('h','k'); 	my_track[24] = Track('i','h'); 	my_track[25] = Track('i','k'); 	my_track[26] = Track('j','h'); 	my_track[27] = Track('j','k'); 	my_track[28] = Track('k','g'); 	my_track[29] = Track('k','h'); 	my_track[30] = Track('k','i'); 	my_track[31] = Track('k','j'); 	my_track[32] = Track('k','l'); 	my_track[33] = Track('l','k'); 	 	 	//Initialize stations 	my_station[0] = Station('a',0,1); 	my_station[1] = Station('b',1,5); 	my_station[2] = Station('c',6,2); 	my_station[3] = Station('d',8,2); 	my_station[4] = Station('e',10,5); 	my_station[5] = Station('f',15,2); 	my_station[6] = Station('g',17,2); 	my_station[7] = Station('h',19,5); 	my_station[8] = Station('i',24,2); 	my_station[9] = Station('j',26,2); 	my_station[10] = Station('k',28,5); 	my_station[11] = Station('l',33,1); 	 }  不好意思啊,写的有点乱,只要的一时能不能拆成三个class文件,老师很烦人,不教课,却教我们写作业, 正在恶补class,constructor,之类的东西. 如果有时间,希望大神能给予帮助和指导,谢谢

user: user-1
content: #include <stdio.h> #include <string.h> #include <stdlib.h>  typedef struct tagPATH { 	tagPATH(const char *Path); 	bool Enable; 	char Begin; 	char End; 	char Name[10]; 	char RevName[10]; } PATH;  PATH::tagPATH(const char *Path) { 	int Length = (int)strlen(Path); 	Enable = true; 	Begin = Path[0]; 	End = Path[Length - 1]; 	strcpy_s(Name, 10, Path); 	for (int i = 0; i < Length; i++) 	{ 		RevName[i] = Name[Length - 1 - i]; 	} 	RevName[Length] = '\0'; }  void SearchPath(char Begin, char End, char **List, int ListSize, PATH *Path, int PathSize) { 	static int _Count = 0; 	if (Begin == End) 	{ 		printf_s("%3d ", ++_Count); 		for (int i = 0; i < ListSize; i++) 		{ 			printf_s("%s ", List[i]); 		} 		printf_s("\n"); 	} 	else 	{ 		for (int i = 0; i < PathSize; i++) 		{ 			if (Path[i].Enable && (Path[i].Begin == Begin || Path[i].End == Begin)) 			{ 				List[ListSize] = Path[i].Begin == Begin ? Path[i].Name : Path[i].RevName; 				Path[i].Enable = false; 				SearchPath(Path[i].Begin == Begin ? Path[i].End : Path[i].Begin, End, List, ListSize + 1, Path, PathSize); 				Path[i].Enable = true; 			} 		} 	} }  int main(void) { 	const int PATH_SIZE = 11; 	char *List[PATH_SIZE]; 	PATH  Path[PATH_SIZE] = {PATH("AB"),PATH("BCE"),PATH("BE"),PATH("BDE"),PATH("BFH"),PATH("EGK"),PATH("EH"),PATH("HIK"),PATH("HK"),PATH("HJK"),PATH("KL")}; 	SearchPath('A', 'L', List, 0, Path, PATH_SIZE);  	system("pause"); 	return 0; }

user: user-0
content: 引用 4 楼 amoyman 的回复:我算了一下，有640种。是这样吧  #include <iostream> #include <vector> using namespace std;  typedef struct tagPATH { 	tagPATH(const char *Path); 	char Begin; 	char End; 	char Name[10]; } PATH;  PATH::tagPATH(const char *Path) { 	int Length = (int)strlen(Path); 	Begin = Path[0]; 	End = Path[Length - 1]; 	strcpy_s(Name, 10, Path); }  void SearchPath(char Begin, char End, vector<int> &memPath, PATH *Path, int Size) { 	static int _Count = 0; 	if (Begin == End) 	{ 		printf_s("%3d ", ++_Count); 		for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 		{ 			printf_s("%s ", Path[*it].Name); 		} 		printf_s("\n"); 		return; 	} 	bool *Enable = new bool[Size]; 	memset(Enable, true, Size); 	for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 	{ 		Enable[*it] = false; 	} 	for (int i = 0; i < Size; i++) 	{ 		if (Enable[i]) 		{ 			if (Path[i].Begin == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].End, End, memPath, Path, Size); 				memPath.pop_back(); 			} 			else if (Path[i].End == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].Begin, End, memPath, Path, Size); 				memPath.pop_back(); 			} 		} 	} 	delete[] Enable; }  // 定义所有的线路  int main(void) { 	const int PATH_SIZE = 11; 	PATH Path[PATH_SIZE] = 	{ 		PATH("AB"), 		PATH("BCE"), 		PATH("BE"), 		PATH("BDE"), 		PATH("BFH"), 		PATH("EGK"), 		PATH("EH"), 		PATH("HIK"), 		PATH("HK"), 		PATH("HJK"), 		PATH("KL") 	}; 	vector<int> memPath; 	SearchPath('A', 'L', memPath, Path, PATH_SIZE);  	system("pause"); 	return 0; }   没事了,十分感谢,可以用,640种应该是对的; 请问您C的版本熟悉么

user: user-0
content: 引用 4 楼 amoyman 的回复:我算了一下，有640种。是这样吧  #include <iostream> #include <vector> using namespace std;  typedef struct tagPATH { 	tagPATH(const char *Path); 	char Begin; 	char End; 	char Name[10]; } PATH;  PATH::tagPATH(const char *Path) { 	int Length = (int)strlen(Path); 	Begin = Path[0]; 	End = Path[Length - 1]; 	strcpy_s(Name, 10, Path); }  void SearchPath(char Begin, char End, vector<int> &memPath, PATH *Path, int Size) { 	static int _Count = 0; 	if (Begin == End) 	{ 		printf_s("%3d ", ++_Count); 		for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 		{ 			printf_s("%s ", Path[*it].Name); 		} 		printf_s("\n"); 		return; 	} 	bool *Enable = new bool[Size]; 	memset(Enable, true, Size); 	for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 	{ 		Enable[*it] = false; 	} 	for (int i = 0; i < Size; i++) 	{ 		if (Enable[i]) 		{ 			if (Path[i].Begin == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].End, End, memPath, Path, Size); 				memPath.pop_back(); 			} 			else if (Path[i].End == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].Begin, End, memPath, Path, Size); 				memPath.pop_back(); 			} 		} 	} 	delete[] Enable; }  // 定义所有的线路  int main(void) { 	const int PATH_SIZE = 11; 	PATH Path[PATH_SIZE] = 	{ 		PATH("AB"), 		PATH("BCE"), 		PATH("BE"), 		PATH("BDE"), 		PATH("BFH"), 		PATH("EGK"), 		PATH("EH"), 		PATH("HIK"), 		PATH("HK"), 		PATH("HJK"), 		PATH("KL") 	}; 	vector<int> memPath; 	SearchPath('A', 'L', memPath, Path, PATH_SIZE);  	system("pause"); 	return 0; }   刚才尝试用你给你的code 跑一下,发现Line 18的Strcpy_s 没有定义? Line26 print_s 好像也是同样的问题. 求大神答疑.

user: user-1
content: 我算了一下，有640种。是这样吧  #include <iostream> #include <vector> using namespace std;  typedef struct tagPATH { 	tagPATH(const char *Path); 	char Begin; 	char End; 	char Name[10]; } PATH;  PATH::tagPATH(const char *Path) { 	int Length = (int)strlen(Path); 	Begin = Path[0]; 	End = Path[Length - 1]; 	strcpy_s(Name, 10, Path); }  void SearchPath(char Begin, char End, vector<int> &memPath, PATH *Path, int Size) { 	static int _Count = 0; 	if (Begin == End) 	{ 		printf_s("%3d ", ++_Count); 		for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 		{ 			printf_s("%s ", Path[*it].Name); 		} 		printf_s("\n"); 		return; 	} 	bool *Enable = new bool[Size]; 	memset(Enable, true, Size); 	for (vector<int>::iterator it = memPath.begin(); it != memPath.end(); it++) 	{ 		Enable[*it] = false; 	} 	for (int i = 0; i < Size; i++) 	{ 		if (Enable[i]) 		{ 			if (Path[i].Begin == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].End, End, memPath, Path, Size); 				memPath.pop_back(); 			} 			else if (Path[i].End == Begin) 			{ 				memPath.push_back(i); 				SearchPath(Path[i].Begin, End, memPath, Path, Size); 				memPath.pop_back(); 			} 		} 	} 	delete[] Enable; }  // 定义所有的线路  int main(void) { 	const int PATH_SIZE = 11; 	PATH Path[PATH_SIZE] = 	{ 		PATH("AB"), 		PATH("BCE"), 		PATH("BE"), 		PATH("BDE"), 		PATH("BFH"), 		PATH("EGK"), 		PATH("EH"), 		PATH("HIK"), 		PATH("HK"), 		PATH("HJK"), 		PATH("KL") 	}; 	vector<int> memPath; 	SearchPath('A', 'L', memPath, Path, PATH_SIZE);  	system("pause"); 	return 0; }

user: user-2
content: 仅供参考//1 2 3 //4 5 6 求一笔划过所有9个键的所有方法 //7 8 9 #include <stdio.h> int g[10][9]={     {0,0,0,0,0,0,0,0,0},     {2,4,5,0,0,0,0,0,0},//1     {1,3,4,5,6,0,0,0,0},//2     {2,5,6,0,0,0,0,0,0},//3     {1,2,5,7,8,0,0,0,0},//4     {1,2,3,4,6,7,8,9,0},//5     {2,3,5,8,9,0,0,0,0},//6     {4,5,8,0,0,0,0,0,0},//7     {4,5,6,7,9,0,0,0,0},//8     {5,6,8,0,0,0,0,0,0},//9 }; int k,i,n; int h[10];//记录是否划过h[1..9],history int p[10];//记录划的顺序p[1..9],path void go(int f,int L) {     int j;      if (L==9) {         p[L]=f;         n++;         printf("%08d:",n);         for (i=1;i<=9;i++) printf(" %d",p[i]);         printf("\n");     } else {         p[L]=f;         h[f]=1;         j=0;         while (1) {             if (g[f][j]==0) break;             if (h[g[f][j]]==0) {                 go(g[f][j],L+1);                 h[g[f][j]]=0;             }             j++;         }     } } int main() {     n=0;     for (k=1;k<=9;k++) {         for (i=1;i<=9;i++) h[i]=0;         go(k,1);     }     return 0; } //00000001: 1 2 3 5 4 7 8 6 9 //00000002: 1 2 3 5 4 7 8 9 6 //00000003: 1 2 3 5 6 9 8 4 7 //00000004: 1 2 3 5 6 9 8 7 4 //00000005: 1 2 3 5 7 4 8 6 9 //00000006: 1 2 3 5 7 4 8 9 6 //00000007: 1 2 3 5 9 6 8 4 7 //00000008: 1 2 3 5 9 6 8 7 4 //00000009: 1 2 3 6 5 4 7 8 9 //00000010: 1 2 3 6 5 7 4 8 9 //00000011: 1 2 3 6 5 9 8 4 7 //00000012: 1 2 3 6 5 9 8 7 4 //00000013: 1 2 3 6 8 4 7 5 9 //00000014: 1 2 3 6 8 7 4 5 9 //00000015: 1 2 3 6 8 9 5 4 7 //00000016: 1 2 3 6 8 9 5 7 4 //00000017: 1 2 3 6 9 5 4 7 8 //00000018: 1 2 3 6 9 5 4 8 7 //00000019: 1 2 3 6 9 5 7 4 8 //00000020: 1 2 3 6 9 5 7 8 4 //00000021: 1 2 3 6 9 5 8 4 7 //00000022: 1 2 3 6 9 5 8 7 4 //00000023: 1 2 3 6 9 8 4 5 7 //00000024: 1 2 3 6 9 8 4 7 5 //00000025: 1 2 3 6 9 8 5 4 7 //00000026: 1 2 3 6 9 8 5 7 4 //00000027: 1 2 3 6 9 8 7 4 5 //00000028: 1 2 3 6 9 8 7 5 4 //00000029: 1 2 4 5 3 6 9 8 7 //00000030: 1 2 4 5 7 8 9 6 3 //00000031: 1 2 4 7 5 3 6 8 9 //00000032: 1 2 4 7 5 3 6 9 8 //00000033: 1 2 4 7 5 8 9 6 3 //00000034: 1 2 4 7 5 9 8 6 3 //00000035: 1 2 4 7 8 5 3 6 9 //00000036: 1 2 4 7 8 5 9 6 3 //00000037: 1 2 4 7 8 6 3 5 9 //00000038: 1 2 4 7 8 6 9 5 3 //00000039: 1 2 4 7 8 9 5 3 6 //00000040: 1 2 4 7 8 9 5 6 3 //00000041: 1 2 4 7 8 9 6 3 5 //00000042: 1 2 4 7 8 9 6 5 3 //00000043: 1 2 4 8 7 5 3 6 9 //00000044: 1 2 4 8 7 5 9 6 3 //00000045: 1 2 4 8 9 6 3 5 7 //00000046: 1 2 5 3 6 9 8 4 7 //00000047: 1 2 5 3 6 9 8 7 4 //00000048: 1 2 5 4 7 8 9 6 3 //00000049: 1 2 5 7 4 8 9 6 3 //00000050: 1 2 6 3 5 4 7 8 9 //00000051: 1 2 6 3 5 7 4 8 9 //00000052: 1 2 6 3 5 9 8 4 7 //00000053: 1 2 6 3 5 9 8 7 4 //00000054: 1 2 6 9 8 4 7 5 3 //00000055: 1 2 6 9 8 7 4 5 3 //00000056: 1 4 2 3 5 6 9 8 7 //... ... //00000776: 9 8 7 4 5 6 3 2 1 //00000777: 9 8 7 5 1 4 2 3 6 //00000778: 9 8 7 5 1 4 2 6 3 //00000779: 9 8 7 5 3 6 2 1 4 //00000780: 9 8 7 5 3 6 2 4 1 //00000781: 9 8 7 5 4 1 2 3 6 //00000782: 9 8 7 5 4 1 2 6 3 //00000783: 9 8 7 5 6 3 2 1 4 //00000784: 9 8 7 5 6 3 2 4 1

user: user-3
content: 排列组合问题。  引用 楼主 geo24 的回复:如果从A站出发到L站,中间路径不可以重复,但是站台可以重复,请问有多少种做法?    希望能用C和C++各一种方法.  这是一个作业,希望可以有经验的前辈给予帮助 .  助教已经给力些帮助,没办法我的底子太差.  #include <stdio.h>    int a[12][12]={0,1,0,0,0,0,0,0,0,0,0,0, 			1,0,1,1,1,1,0,0,0,0,0,0, 			0,1,0,0,1,0,0,0,0,0,0,0,                         0,1,0,0,1,0,0,0,0,0,0,0, 		        0,1,1,1,0,0,1,1,0,0,0,0, 			0,1,0,0,0,0,0,1,0,0,0,0,                         0,0,0,0,1,0,0,0,0,0,1,0, 		        0,0,0,0,1,1,0,0,1,1,1,0, 		        0,0,0,0,0,0,0,1,0,0,1,0,                         0,0,0,0,0,0,1,1,0,0,1,0, 		        0,0,0,0,0,0,0,1,1,1,0,1, 		        0,0,0,0,0,0,0,0,0,0,1,0                 }; 	void SearchRoute(int row, int col) 	{ 		        if()            //find a succseful route to L 		{ 			...		//ADD 1 into varibale  			 			...		//print out this route 					 			return; 		} 		 		        else {  //Get into recursive Function Body 			 			      while(col < 12) // becuase "11" is the ending point L 			{ 				....  //Find one possible step (push stack) 				 				.... // save this step & make it used 				 				SearchRoute(col, 0); 				 				...		// Backtrack this step, 1-0-1 (pop stack) 				 				col++; 			} 			 		} 	}    void main ()  { 	   }

user: user-2
content: “给定一个小点的输入，完整单步跟踪(同时按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史)一遍。”是理解递归函数工作原理的不二法门！ 递归函数关注以下几个因素 ·退出条件 ·参数有哪些 ·返回值是什么 ·局部变量有哪些 ·全局变量有哪些 ·何时输出 ·会不会导致堆栈溢出