题解 | #配置文件恢复#

配置文件恢复

https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

// HJ66-2 配置文件恢复.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
	string str;
	string signal = "reset";
	vector<vector<string>>dp = { {"reset","board","board fault"},{"board","add","where to add"},
		{"board","delete","no board at all"},{"reboot","backplane","impossible"},{"backplane","abort","install first"} };
	while (getline(cin, str))
	{
		int n = count(str.begin(),str.end(),' ');
		if (n == 0)
		{
			if (signal.find(str) == 0)
			{
				cout << "reset what" << endl;
			}
			else
			{
				cout << "unknown command" << endl;
			}
		}
		else
		{
			int count = 0; string res = "";
			int x = str.find(' ');
			string str1 = str.substr(0, x);
			string str2 = str.substr(x + 1);
			for (int i = 0; i < 5; i++)
			{
				if (dp[i][0].find(str1) == 0 && dp[i][1].find(str2) == 0)
				{
					res = dp[i][2];
					count++;
					continue;
				}
			}
			if (count == 1)
			{
				cout << res << endl;
			}
			else
			{
				cout << "unknown command" << endl;
			}
		}
	}
	return 0;
}

全部评论

相关推荐

07-07 17:06
已编辑
深圳技术大学 golang
您好请问贵司招切图仔...:b站的录用通知好中二
点赞 评论 收藏
分享
程序员小白条:学历和简历问题,你想走开发,现在很难的啦,尤其后端方向很难走,前端、测开,都会好很多,另外要等8月底和9月初去投日常
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务