猛攻大模拟day3!!

权限查询 没啥好说的 map套。但是很多小细节,还是debug了很久,而且中间还卡在一个地方,因为写出了 cout<

vector中的find map中的count

代码如下

#include
#include
#include
#include
using namespace std;
map per;
map> role;
map>user;
void work()
{
	int p;
	cin >> p;
	for (int i = 0; i < p; i++)
	{
		string str;
		cin >> str;
		int it = str.find(":");
		if (it == -1)
		{
			per[str] = 10;
		}
		else
		{
			per[str.substr(0, it)] = stoi(str.substr(it + 1));
		}
	}
	int r;
	cin >> r;
	for (int i = 0; i < r; i++)
	{
		string str;
		cin >> str;
		int s;
		cin >> s;
		for (int j = 0; j < s; j++)
		{
			string privi;
			cin >> privi;
			int it = privi.find(":");
			if (it == -1)
			{
				role[str][privi] = 10;
			}
			else
			{
				string st = privi.substr(0, it);
				//cout << st << endl;
				if (role[str].find(st) != role[str].end())
				{
					int num = stoi(privi.substr(it + 1));
					if (role[str][st] < num)role[str][st] = num;
				}
				else
				{
					role[str][st] = stoi(privi.substr(it + 1));
					//cout << role[str][privi] << endl;
					//cout << str << " " << privi << " " << role[str][privi] << "xixi" << endl;
				}
			}
		}
	}
	int u;
	cin >> u;
	for (int i = 0; i < u; i++)
	{
		string str;
		cin >> str;
		int t;
		cin >> t;
		for (int j = 0; j < t; j++)
		{
			string st;
			cin >> st;
			user[str].emplace_back(st);
		}
	}
	//cout << role["hr"]["crm"] << endl;
	int q;
	cin >> q;
	//for (auto p : per)cout << p.first << p.second<> str >> st;
		int it = st.find(":");
		if (it == -1)//无权限查询
		{
			//cout << "xixi" << endl;
			if (per.find(st) == per.end())
			{
				
				cout << "false" << endl;
				continue;
			}
			if (per[st]==10)
			{
				bool flag = false;
				for (int j = 0; j < user[str].size(); j++)
				{
					string st1 = user[str][j];
					if (role[st1].find(st) != role[st1].end())flag = true;

				}
				if (flag)puts("true");
				else puts("false");
			}
			else//返回最大等级
			{
				bool flag = false;
				int max_num = 0;
				for (int j = 0; j < user[str].size(); j++)
				{
					string st1 = user[str][j];
					if (role[st1].find(st) != role[st1].end())
					{
						max_num = max(max_num, role[st1][st]);
						flag = true;
					}
				}
				if (flag)
					cout << max_num << endl;
				else cout << "false" << endl;
			}
		}
		else
		{
			string st1 = st.substr(0, it);
			int num = stoi(st.substr(it + 1));
			//cout << st1 << " " << num << endl;
			bool flag = false;
			bool flag1 = false;
			for (int j = 0; j < user[str].size(); j++)
			{
				string st2 = user[str][j];
				//cout << role[st2][st1] << endl;
				//cout << role["hr"]["crm"] << endl;
				if (role[st2].find(st1) != role[st2].end())
				{
					flag1 = true;
					if (role[st2][st1] >= num)
					{
						flag = true;
					}
				}
			}
			if (flag1)
			{
				if (flag)cout << "true" << endl;
				else cout << "false" << endl;
			}
			else
			cout << "false" << endl;
		}
	}
}
int main()
{
	work();
	return 0;
}

markdown 偷懒啦嘻嘻 因为一会要健身 所以这题看着别人答案写了一遍,感觉还行,就是要注意逻辑。嵌套只有一层。555 下午一定好好努力。先健身去了

#include
using namespace std;
vectors;
string str;
int is_link(string str, int i);
int is_em(string str,int i)
{
    cout << "";
    for (i++; str[i] != '_'; i++)//跳过'_'
    {
        char c = str[i];
        if (c == '[') i=is_link(str,i);
        else cout << c;
    }
    cout<<"";
    return i;
}

int is_link(string str,int i)
{
    string link, text;
    for (i++; str[i] !=']'; i++)//跳过'['
    {
        char c = str[i];
        if (c == '_') {
            i++;
            text += "";//强调开始
            while (str[i] != '_') text += str[i++];
            text += "";
        }
        else text += c;
    }
    i += 2;//']''('
    while (str[i] != ')') {
        char c = str[i++];
        link += c;
    }
    cout << "" << text << "";
    return i;
}
void work_line(string str)//按行处理
{
    int i = 0;//跳过空格
    while (str[i] == ' ') i++;
    str = str.substr(i);

    for (int i = 0; i < str.size(); i++)//判断这一行是什么操作
    {
        char c = str[i];
        if (c == '_') i = is_em(str,i);
        else if (c == '[') i = is_link(str,i);
        else cout << c;
    }
}
void work(int a, int b)//处理区块
{
    if (s[a][0] == '#') //标题
    {
        int cnt = 0;
        while (s[a][cnt] == '#') cnt++;
        cout << "" ;
        work_line(s[a].substr(cnt));
        cout << "" << endl;
    }
    else if (s[a][0] == '*') //无序号
    {
        puts("
    "); for (int i = a; i <= b; i++) { cout << "
  • "; work_line(s[i].substr(1)); puts("
  • "); } puts("
"); } else { cout << "

"; for (int i = a; i < b; i++) { work_line(s[i]); cout << endl; } work_line(s[b]); puts("

"); } } int main() { while (getline(cin, str)) s.push_back(str); for (int i = 0; i < s.size(); i++) { if (s[i].size() == 0) continue;//跳过空行 else { int j = i; while (j < s.size() && s[j].size() != 0) j++;//找到一段 work(i, j - 1);//处理[i,j]段 i = j;//处理下一段 } } }

DHCP服务器

带配额的文件系统 这题是真的难啊难啊难

静不下心了 明天看运气吧 长达一个月的CCF-CSP备考 结束啦

你可能感兴趣的:(c++,算法,图论)