⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kevinmain.cc

📁 Computes the distance between kevin bacon and other actors (six degrees of seperation).
💻 CC
字号:
#include <string>#include <iostream>#include <vector>#include <iterator>#include <fstream>#include <string>#include "graph.h"using namespace std;//This program performs the idea of six degrees of Kevin Bacon.  It takes an input file that has an//  actors name, then a movie, then another actor that was in that movie, each seperated by a //  semicolon.  The program first reads in each line of the file and stores it.  It then parses//  each line into the two actors and the movie.  The program then calls addEdge on the two actors.//  The graph I chose to use was an undirected and unweighted so the movie was not used.  After I have //  the graph created I call the dotOutput function in the graph.h program to create an image of//  the file that was input.  I then call the breadth first search on Kevin Bacon since he is//  the person were trying to connect to everyone.int main(int argc, char* argv[]){   graph<string, undirected, unweighted> kevin;  //Creates the undirected unweighted graph     int num =0;   vector< string> input;	//Vector for reading in   string line;   ifstream inFile(argv[1]);     while(!inFile.eof())     {	getline(inFile, line);		//Gets each line of the file and stores them in a vector	input.push_back(line);	num++;   }   inFile.close();       string a1;   string a2;			//Used in the parsing of the file   string a3;   string a4;   string a5;   cout<<endl;   for(int k=0; k<num; k++)	//Goes through each line of the vector   {	a1 = input[k];				for(int i=0; i<a1.length(); i++)        {           if(a1[i] == ';')     	//Seperates the line into at the first actor and the other part           {                                  a3 = a1.substr(0, i);		a2 = a1.substr(i+1, a1.length()-1);		for(int j=0; j<a2.length(); j++)		{		    if(a2[j] == ';')		//Seperates the other part into the movie and the 		    {				//  second actor		   	a4 = a2.substr(0, j);		    	a5 = a2.substr(j+1, a2.length()-1);			j=a2.length();		    }		}           	          i=a1.length();	    }        }	kevin.addEdge(a3, a5);		//Buts the actors in the graph with addEdge    }        	kevin.dotOutput("kgrone.dot");	//Creates the dot file    cout << "Name                       Bacon Number" << endl;	//Format of the output    cout << "---------------------------------------" << endl;	kevin.BFS("Kevin Bacon");				//Calls the breadth first search    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -