ACM:网页导航
ACM: Web Navigation
注意:我写的这个问题只是为了解ACM问题的人准备的。
我对这个问题有问题。我为此写了一个很好的解决方案,但每次发送时都会得到错误的答案。我不知道这里出了什么问题。我针对许多测试用例测试了此代码。你能帮我修复我的代码吗?
这是问题的链接:http://sharecode.ir/section/problemset/problem/1022。
这是我的代码:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
string page[1000] = { "" };
int cntr = 0;
page[cntr] = "http://www.acm.org/";
string page1;
while (1)
{
cin >> page1;
if (page1 == "QUIT")
break;
if (page1 == "VISIT")
{
cntr++;
cin >> page1;
page[cntr] = page1;
cout << page1 << endl;
}
if (page1 == "BACK")
{
cntr--;
if (cntr >= 0)
cout << page[cntr] << endl;
else
{
cout << "Ignored" << endl;
cntr = 0;
}
}
if (page1 == "FORWARD")
{
cntr++;
if (page[cntr] == "")
cout << "Ignored" << endl;
else
cout << page[cntr] << endl;
}
}
if (n) cout << endl;
}
}
访问网站后不会清除转发。这就是为什么你会得到错误的答案。
这是正确的代码:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int n){
cin >> n;
while (n--){
string c;
vector <string> a(999," ");
a[0] = "http://www.acm.org/";
int i = 0;
while(cin>>c,c != "QUIT"){
if (c == "VISIT"){
i++;
string s;
cin >> s;
a[i] = s;
cout << a[i] << "n";
int t = i+1;
while (a[t] != " ") {
a[t] = " ";
t++;
}
}
if (c == "BACK"){
i--;
if (i < 0) {cout << "Ignoredn"; i=0;} else cout << a[i] << "n";
}
if (c == "FORWARD"){
i++;
if (a[i] == " ") {cout << "Ignoredn"; i--;} else cout << a[i] << "n";
}
}
if (n) cout << "n";
}
}
相关文章:
- 在 emscripten 网页汇编正在运行期间更新进度条?
- 如何使用QT创建器获取网页源代码?
- 导航 while 循环
- Qt 网页程序集缓存
- 如何在C++中获取重定向网页的URL
- 如何在OSX上导航到用户输入站点?
- 如何在vim中导航c++模板实例化
- 你能把整个网页嵌入到c++源代码中吗
- WinInet只下载网页的一部分
- 重定向到 C++ 中的网页
- 在 c++ winrt 导航视图中,如何找到选择/单击的导航项?
- 为什么这种在数组中导航的方法是错误的?
- Emacs 标签/导航在 Windows 上?
- QWebEngine 5.7.1 离线导航加载缓存
- 是否有安全的导航操作员C++?
- 获取从网页到 c++ 的 json 响应
- vim 标签导航,使用 VIM 或 CTAG 更改排序顺序
- 如何在C ++(qt)代码中使用python脚本?(网页抓取方面)
- ARDUINO LCD:通过读取数组生成导航菜单
- ACM:网页导航