标签:
自己写的代码,供大家参考一下
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
//#include <cstdio.h>
#include <string>
#include <map>
using namespace std;
struct kenerl
{
int major;
int mirror;
int level;
};
kenerl getKernel(string str)
{
int len = str.length();
int i = 0;
vector<int> temp(3,-1);
int index = 0;
while (i<len)
{
int number = 0;
while(i<len && str[i]!=‘.‘)
{
number= number*10+ (str[i]-‘0‘);
i++;
}
temp[index]= number;
index++;
i++;
}
kenerl res;
res.major = temp[0];
res.mirror = temp[1];
res.level = temp[2];
return res;
}
int main()
{
int n;
cin>>n;
vector<string> dict;
if (n==0)
{
cout<<"no stable available"<<endl;
return 0;
}
for (int i = 0; i<= n;i++)
{
string buf;
getline(cin,buf);
//cout<<buf<<endl;
dict.push_back(buf);
}
/*map<int,vector<kenerl>> dictKenerl;*/
kenerl maxKenerl;
maxKenerl.major = -1;
maxKenerl.mirror = -1 ;
maxKenerl.level = -1;
for (int i =1;i<dict.size();i++)
{
string temp = dict[i];
kenerl num = getKernel(temp);
if (num.mirror%2==0)//mirror 2
{
if (num.major>maxKenerl.major)//
{
maxKenerl = num;
}else if (num.major == maxKenerl.major)
{
if (num.mirror>maxKenerl.mirror)
{
maxKenerl = num;
}else if(num.mirror == maxKenerl.mirror)
{
if (num.level>=maxKenerl.level)
{
maxKenerl = num;
}
}else
{
//xiaoyu
}
}
else
{
//xiaoyu
}
}
}
//string res;
//int nTemp =0;
//std::stringstream ss;
//string strTest;
if (maxKenerl.major >0)
{
cout<<maxKenerl.major;
}
if (maxKenerl.mirror>0)
{
cout<<"."<<maxKenerl.mirror;
}
if (maxKenerl.level>0)
{
cout<<"."<<maxKenerl.level;
}
if (maxKenerl.major == -1 && maxKenerl.level ==-1 && maxKenerl.mirror ==-1)
{
cout<<"no stable available"<<endl;
}
cout<<endl;
system("pause");
return 0;
}
2016去哪网笔试题一
标签:
原文地址:http://www.cnblogs.com/lishichao/p/4829377.html