//超時(shí)啦!
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Stu_info
{
public:
Stu_info() = delete;
Stu_info(string &s, unsigned r) :id(s), rank(r) {};
unsigned get_rank() const { return rank; }
bool get_checked() const { return checked; }
string get_id() const { return id; }
void check() { checked = true; }
private:
string id;
unsigned rank = 0;
bool checked = false;
};
bool prime_number(unsigned u)
{
bool ret = true;
if (u == 2)
{
return ret;
}
for (unsigned i = 2; i < u; ++i) //循環(huán)令u除以比自身小的所有數(shù)字(2》u-1),如果能整除,則不是素?cái)?shù)。返回false!
{
if ((u%i) == 0)
ret= false;
}
return ret; //如果通過判斷條件,則是素?cái)?shù),返回true!
}
int main()
{
unsigned n;
cin >> n;
vector<Stu_info> data;
for (unsigned i = 0; i < n; ++i)
{
string tmp;
cin >> tmp;
data.push_back(Stu_info(tmp, (i + 1))); //(i+1)為常量表達(dá)式!
}
unsigned k;
cin >> k;
for(unsigned i=0;i<k;++i)
{
string tmp;
cin >> tmp;
bool has_find = false;
for (auto &r : data)
{
if (tmp == r.get_id())
{
has_find = true;
auto rank = r.get_rank();
if (r.get_checked())
{
cout <<r.get_id()<< ": Checked";
}
else
{
if (rank == 1)
{
cout<<r.get_id()<<": Mystery Award";
}
else
{
if(prime_number(rank))
cout<< r.get_id() << ": Minion";
else
cout << r.get_id() << ": Chocolate";
}
r.check();
}
}
}
if (!has_find) //循環(huán)結(jié)束后,如果找到了has_find為true!
{
cout << tmp<<": Are you kidding?";
}
if (i != (k - 1))
{
cout << endl;
}
}
system("pause");
return 0;
}
//同樣超時(shí)!各種容器的效率問題?
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Stu_info
{
public:
Stu_info() = delete;
Stu_info(string &s, unsigned r) :id(s), rank(r) {};
bool get_checked() const { return checked; }
string get_id() const { return id; }
string get_award();
private:
string id;
unsigned rank = 0;
bool checked = false;
bool prime_number(unsigned u) ;
};
string Stu_info::get_award()
{
string tmp;
if (!checked)
{
checked = true;
if (rank == 1)
tmp = "Mystery Award";
else
{
if (prime_number(rank))
tmp = "Minion";
else
tmp = "Chocolate";
}
}
else
tmp = "Checked";
return tmp;
}
bool Stu_info::prime_number(unsigned u)
{
bool ret = true;
if (u == 2)
{
return ret;
}
for (unsigned i = 2; i < u; ++i) //循環(huán)令u除以比自身小的所有數(shù)字(2》u-1),如果能整除,則不是素?cái)?shù)。返回false!
{
if ((u%i) == 0)
ret = false;
}
return ret; //如果通過判斷條件,則是素?cái)?shù),返回true!
}
int main()
{
unsigned n;
cin >> n;
vector<Stu_info> data;
for (unsigned i = 0; i < n; ++i)
{
string tmp;
cin >> tmp;
data.push_back(Stu_info(tmp, (i + 1))); //(i+1)為常量表達(dá)式!
}
unsigned k;
cin >> k;
for(unsigned i=0;i<k;++i)
{
string tmp;
cin >> tmp;
bool has_find = false;
for (auto &r : data)
{
if (tmp == r.get_id())
{
has_find = true;
cout << tmp << ": " << r.get_award();
}
}
if (!has_find) //循環(huán)結(jié)束后,如果找到了has_find為true!
{
cout << tmp<<": Are you kidding?";
}
if (i != (k - 1))
{
cout << endl;
}
}
system("pause");
return 0;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。