中国科学院软件研究所软件工程技术中心2007年硕士研究生复试上机题

1202人阅读 评论(0)
今年考上中科院软件所了，便把复试时的上机题分享，算法共欣赏，代码相与析。

题目是这样的：

1.Mission Impossible 3》，演员3人，分别为：Tom CruiseMaggie QJeff Chase

2.War Of The Worlds》，演员2人，分别为：Tom CruiseDakota Fanning

3.Shark Tale》演员3人，分别为：Jack BlackRobert DeNiroWill Smith

4.Hide And Seek》，演员2人，分别为：Dakota FanningRobert DeNiro

5.The Adventure Of Pluto Nash》，演员2人，分别为：Will SmithEddie Murphy

6.Show Time》，演员2人，分别为：Robert DeNiroEddie Murphy

#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <iterator>
#include <functional>
#include <string>
#include <fstream>
#include <iostream>

using namespace std;

class CProblem
{
public:
void Print();
void Solve();
void GetFilm(string Actor,set<string>& FilmSet);
CProblem(char* filename);
virtual ~CProblem();
protected:
multimap<string,string,less<string> >ActorFilmMap;
set<string>ActorSet;
};

CProblem::CProblem(char* filename)
{
ifstream fin(filename);
if(!fin)
{
cerr<<"File not open!"<<endl;
exit(1);
}
string ActorName,FilmName;
int ActorNum;
while(getline(fin,FilmName,'/n'))
{
fin>>ActorNum;
getline(fin,ActorName,'/n');
for(int i=0;i<ActorNum;i++)
{
getline(fin,ActorName,'/n');
ActorFilmMap.insert(make_pair(ActorName,FilmName));
ActorSet.insert(ActorName);
}
getline(fin,FilmName,'/n');
}
fin.close();
}

CProblem::~CProblem()
{

}

{
set<string>ActorSet1,ActorSet2;

set<string>::iterator Iter1,Iter2;
for(Iter1=ActorSet1.begin();Iter1!=ActorSet1.end();Iter1++)
for(Iter2=ActorSet2.begin();Iter2!=ActorSet2.end();Iter2++)
{
if(*Iter1!=*Iter2 && actor1!=*Iter2 && actor2!=*Iter1)
{
set<string,less<string> >FilmSet1,FilmSet2;
GetFilm(*Iter1,FilmSet1);
GetFilm(*Iter2,FilmSet2);

set<string>::iterator Iter3,Iter4;
for(Iter3=FilmSet1.begin();Iter3!=FilmSet1.end();Iter3++)
for(Iter4=FilmSet2.begin();Iter4!=FilmSet2.end();Iter4++)
if(*Iter3==*Iter4)
return true;
}
}
return false;
}

{
set<string>FilmSet;
GetFilm(Actor,FilmSet);

set<string>::iterator Iter1;
multimap<string,string>::iterator Iter2;
for(Iter1=FilmSet.begin();Iter1!=FilmSet.end();Iter1++)
for(Iter2=ActorFilmMap.begin();Iter2!=ActorFilmMap.end();Iter2++)
{
if(*Iter1==Iter2->second && Actor!=Iter2->first)
ActorSet.insert(Iter2->first);
}

}

void CProblem::GetFilm(string Actor,set<string>& FilmSet)
{
multimap<string,string>::iterator Iter1;
for(Iter1=ActorFilmMap.lower_bound(Actor);Iter1!=ActorFilmMap.upper_bound(Actor);Iter1++)
{
FilmSet.insert(Iter1->second);
}
}

void CProblem::Solve()
{
set<string>::iterator Iter1,Iter2;
for(Iter1=ActorSet.begin();Iter1!=ActorSet.end();Iter1++)
{
for(Iter2=ActorSet.begin();Iter2!=ActorSet.end();Iter2++)
{
if(*Iter2==*Iter1)
continue;
cout<<*Iter1<<" and "<<*Iter2<<" are of link 3."<<endl;
}
cout<<endl;
}
}

void CProblem::Print()
{
multimap<string,string>::iterator Iter1;
for(Iter1=ActorFilmMap.begin();Iter1!=ActorFilmMap.end();Iter1++)
cout<<Iter1->first<<" "<<Iter1->second<<endl;
}
int main()
{
CProblem prob("data.txt");
prob.Solve();

system("PAUSE");
return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

data.txt:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

MissionImpossible3
3
TomCruise
MaggieQ
JeffChase

WarOfTheWorlds
2
TomCruise
DakotaFanning

SharkTale
3
JackBlack
RobertDeNiro
WillSmith

HideAndSeek
2
DakotaFanning
RobertDeNiro

2
WillSmith
EddieMurphy

ShowTime
2
RobertDeNiro
EddieMurphy

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：1487次
• 积分：25
• 等级：
• 排名：千里之外
• 原创：1篇
• 转载：0篇
• 译文：0篇
• 评论：0条
文章分类
文章存档
阅读排行