weixin_42054580 2023-07-19 16:37 采纳率: 80%
浏览 126
已结题

XJOI 1 级 21 段 c++ 上网

img

img


约定:
所有的网址都没有空格,最长的网址为70

总的操作次数不超过1000

原代码:

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<stdlib.h>
#include<time.h>
//#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<deque>
using namespace std;
string a[1001];
string b;
int main(){

    a[0]="http://www.hzxjhs.com/";
    int j=1;
    while(cin>>b){        
        if(b=="VISIT"){
            cin>>a[j];
            cout<<a[j]<<endl;
            j++;
        }else if(b=="BACK") cout<<a[--j]<<endl;
        else if(b=="FORWARD") cout<<a[++j]<<endl;
        else if(b=="QUIT") break;
        else cout<<"Ignored"<<endl;
    }

    return 0;
}


结果(全错):

compiled successfully
time: 7ms, memory: 3544kb, score: 0, status: Wrong Answer
> test 1: time: 1ms, memory: 3532kb, points: 0, status: Wrong Answer
> test 2: time: 0ms, memory: 3540kb, points: 0, status: Wrong Answer
> test 3: time: 2ms, memory: 3392kb, points: 0, status: Wrong Answer
> test 4: time: 1ms, memory: 3400kb, points: 0, status: Wrong Answer
> test 5: time: 1ms, memory: 3532kb, points: 0, status: Wrong Answer
> test 6: time: 0ms, memory: 3440kb, points: 0, status: Wrong Answer
> test 7: time: 0ms, memory: 3304kb, points: 0, status: Wrong Answer
> test 8: time: 1ms, memory: 3532kb, points: 0, status: Wrong Answer
> test 9: time: 1ms, memory: 3544kb, points: 0, status: Wrong Answer
> test 10: time: 0ms, memory: 3376kb, points: 0, status: Wrong Answer

请改一改,谢谢。

  • 写回答

3条回答 默认 最新

  • threenewbee 2023-07-19 16:39
    关注

    这个程序我写过,一个数组肯定是不够的,需要起码2个(模拟2个堆栈)
    一个是放之前的,一个是back以后用于forward恢复的

    #include<iostream>
    #include<iomanip>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<string>
    #include<stdlib.h>
    #include<time.h>
    //#include<bits/stdc++.h>
    #include<stack>
    #include<queue>
    #include<deque>
    using namespace std;
    string a[1001];
    string a1[1001];
    string b;
    int main(){
     
        int j=1, j1 = 0;
        a[0]="http://www.hzxjhs.com/";
        while(cin>>b){        
            if(b=="VISIT"){
                cin>>a[j];
                cout<<a[j]<<endl;
                j++;
                j1 = 0;
            }else if(b=="BACK" && j > 1) {
                a1[j1++] = a[--j];
                cout<<a[j - 1]<<endl;
            }
            else if(b=="FORWARD" && j1 > 1) {
                a[j++] = a1[--j];
                cout<<a1[j1 - 1]<<endl;
            }
            else if(b=="QUIT") break;
            else cout<<"Ignored"<<endl;
        }
     
        return 0;
    }
     
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月19日
  • 创建了问题 7月19日

悬赏问题

  • ¥15 wpf通过绑定控件自身的值,来实现背景颜色的切换
  • ¥15 CDH6.3 运行hive -e hive -e "show databases;"报错:hive-env.sh:行24: hbase-common.jar: 权限不够
  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线