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

请改一改,谢谢。

这个程序我写过,一个数组肯定是不够的,需要起码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;
}
 

这题if判断应该能出来吧

还有一题:
  XJOI 1-21 学军电影院



学军电影院暑期档大片“学军熊猫”正在热映,票价25元,现在有很多oier即将来买票,oier都是极简主义者,因此每个人手里只有一张纸币,纸币的面值是100,50,25当中的一种,学军中学已经实现了自动售票,电影院门口放了一台自动售票机,但不巧的是,今天自动售票机里面没有零钱了,现在问你,已知n个oier所带的纸币的信息,以及他们到来的顺序,自动售票机能否在没有钱的情况下完成找钱功能。

(假设纸币投入机器后,会在下一个买票人之前,由工作人员换为对应数量的1元零钱。例如第一个人将1张25元的纸币投入机器后,在第二个人买票时,机器里是25个1元的零钱)

输入格式:
多组测试数据。

每组测试数据先输入一个n,表示买票的总人数,接下来一行输入n个正整数。表示每个人手里的纸币面值。

 

输出格式:
对于每组测试数据

输出”YES”,如果可以完成找钱功能

输出”NO”,如果不能完成找钱功能。

 



样例输入:
4
25 25 50 50
2
25 100
4
50 50 25 25
 

样例输出:
YES
NO
NO



 

约定:
1<=n<=105
 

提示:
第一组数据:先来了两个人手里都有25元钱,都不用找,现在机器里面一共有了两张25,接下来两个人手里都有一张50,每个人分别找回去25。找钱成功。

第二组数据:第一个人来,不用找钱,第二个人来,要找75,发现零钱不够了,所以找钱失败。

第三组数据:第一个人给50,机器里面一开始没有钱,没法找零,所以找钱失败。




原代码:


#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;
int main(){
 
    int n;
    while(cin>>n){
        int a[1001]={},sum=0;
        for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<n;i++){
            if(a[i]==25) sum+=25;
            else if(a[i]==50){
                if(sum<25){
                    cout<<"NO"<<endl;
                    break;
                }
            }else if(a[i]==100){
                if(sum<75){
                    cout<<"NO"<<endl;
                    break;
                }
            }
        }
        cout<<"YES"<<endl;
    }
 
    return 0;
}



结果(错7个):


compiled successfully
time: 4ms, memory: 3400kb, score: 30, status: Wrong Answer
> test 1: time: 1ms, memory: 3372kb, points: 0, status: Wrong Answer
> test 2: time: 1ms, memory: 3352kb, points: 0, status: Wrong Answer
> test 3: time: 1ms, memory: 3364kb, points: 10, status: Accepted
> test 4: time: -1ms, memory: -1kb, points: 0, status: Runtime Error
> test 5: time: -1ms, memory: -1kb, points: 0, status: Runtime Error
> test 6: time: 0ms, memory: 3212kb, points: 10, status: Accepted
> test 7: time: 1ms, memory: 3352kb, points: 0, status: Wrong Answer
> test 8: time: 1ms, memory: 3212kb, points: 0, status: Wrong Answer
> test 9: time: 0ms, memory: 3348kb, points: 0, status: Wrong Answer
> test 10: time: 1ms, memory: 3400kb, points: 10, status: Accepted