1、3、10RE,其余WA,0分求助!!!
查看原帖
1、3、10RE,其余WA,0分求助!!!
373226
justinjia楼主2021/1/20 14:50

既然你们不让我秀LaTeX\LaTeX了,我就不秀了,来点正经的。

我把这个程序放到Dev-C++里运行一遍,结果:

1
2 O(1)
F i 1 1
E
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::erase: __pos (which is 18446744073709551615) > this->size() (which is 0)

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

--------------------------------
Process exited after 26.62 seconds with return value 3
请按任意键继续. . .

44行是输入,后面是报错信息,代码:

#include"stdio.h"
#include"iostream"
#include"string"
#include"string.h"
using namespace std;
bool check_err(string code){
	int buckets[26];
	memset(buckets,0,sizeof(buckets));
	int cnt=0;
    for(int i=0;i<code.size();i++){
        if(code[i]=='F'){
        	cnt++;
        	buckets[code[i+2]-'a']++;
        }else if(code[i]=='E')
            cnt--;
    }
    if(cnt)
    	return 1;
    for(int i=0;i<26;i++)
    	if(buckets[i]>1)
    		return 1;
    return 0;
}
bool check_time(string code,string time_){
    time_.erase(0,2);//擦除O(
    time_.erase(time_.size()-1,1);//擦除)
    int _time;
    if(time_=="1")
    	_time=0;
    else{
    	time_.erase(0,2);//擦除n^
    	_time=0;
    	for(int i=0;i<time_.size();i++){
    		_time+=time_[i];
    		_time*=10;
		}
	}
    int correct_time=0,cnt=0;
    int flag=-1;
    for(int i=0;i<code.size();i++){
    	if(code[i]=='F'){
    		string a="",b="";
    		for(int j=i+4;code[j]>='0'&&code[j]<='9'||code[j]=='n';j++){
    			a+=code[j];
    			code.erase(j,1);
			}
			a.erase(a.size()-1,1);
			for(int j=i+4;code[j]>='0'&&code[j]<='9'||code[j]=='n';j++){
				b+=code[j];
				code.erase(j,1);
			}
			b.erase(b.size()-1,1);
			if(a=="n"&&b=="n"){}
			else if(a=="n"&&b!="n")
				flag=cnt;
			else if(cnt<=flag&&a!="n"&&b=="n")
				cnt++;
			else{
				int A=0,B=0;
				for(int j=0;j<a.size();j++){
					A+=a[j]-'0';
					A*=10;
				}
				for(int j=0;j<b.size();j++){
					B+=b[j]='0';
					B*=10; 
				}
				if(A<B)
					flag=cnt;
				else if(cnt<=flag)
					cnt++;
			}
		}else if(code[i]=='E'){
			cnt--;
			if(cnt<=flag)
				flag=-1;
		}
		if(cnt>correct_time)
			correct_time=cnt;
	}
	return correct_time==_time;
}
int main(void){
    int t;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        string code="",time_,tmp;
        int line;
        scanf("%d",&line);
        cin>>time_;
        getline(cin,tmp);
        for(int j=0;j<line;j++){
            getline(cin,tmp);
            code+=tmp;
        }
        if(check_err(code))
            printf("ERR\n");
        else if(check_time(code,time_))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

不会是因为我码量太高了吧?

2021/1/20 14:50
加载中...