我为 uva 问题 5355 解决了一个链接: https ://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=3356&mosmsg=Submission+received+with+ID+1242500 ?
我提出了解决方案,它在我的电脑上运行良好,我使用了整体 dev c++ IDE,但是当我在 uva 网站上提交程序时,他们给了我一条消息运行时错误。这是我寄给我的
“您提交的编号为 1242500 的问题 5355 - Baudot 数据通信代码因判定运行时错误而失败。
这意味着您的程序的执行没有正确完成。请记住始终以退出代码 0 终止您的代码。”
我检查了我的程序在我的电脑上运行良好,所以为了检查我去了http://www.compileonline.com/并尝试在线编译它。
它给了我一个运行时错误,在抛出 'std::out_of_range' what(): basic_string::substr 的实例后调用终止
请你检查一下我的程序有什么问题,我正在粘贴源代码。
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stdio.h>
using namespace std ;
int main(){
char check ;
int i = 0 ;
struct forbinary{
char ds;
char us;
char bin[20];
}b[35] ;
char type = 'd' ;
strcpy(b[0].bin,"00000");
strcpy(b[1].bin,"00001");
strcpy(b[2].bin,"00010");
strcpy(b[3].bin,"00011");
strcpy(b[4].bin,"00100");
strcpy(b[5].bin,"00101");
strcpy(b[6].bin,"00110");
strcpy(b[7].bin,"00111");
strcpy(b[8].bin,"01000");
strcpy(b[9].bin,"01001");
strcpy(b[10].bin,"01010");
strcpy(b[11].bin,"01011");
strcpy(b[12].bin,"01100");
strcpy(b[13].bin,"01101");
strcpy(b[14].bin,"01110");
strcpy(b[15].bin,"01111");
strcpy(b[16].bin,"10000");
strcpy(b[17].bin,"10001");
strcpy(b[18].bin,"10010");
strcpy(b[19].bin,"10011");
strcpy(b[20].bin,"10100");
strcpy(b[21].bin,"10101");
strcpy(b[22].bin,"10110");
strcpy(b[23].bin,"10111");
strcpy(b[24].bin,"11000");
strcpy(b[25].bin,"11001");
strcpy(b[26].bin,"11010");
strcpy(b[27].bin,"11011");
strcpy(b[28].bin,"11100");
strcpy(b[29].bin,"11101");
strcpy(b[30].bin,"11110");
strcpy(b[31].bin,"11111");
FILE *fp ;
fp = fopen("inp.txt","r");
char str[401] ;
string temp , temp2;
fgets(str,80,fp);
int j = strlen(str) ;
for(i=0;i<j-1;i++){
b[i].ds = str[i] ;
}
fgets(str,80,fp);
for(i=0;i<j-1;i++){
b[i].us = str[i] ;
}
int x = 0 , y = 0,z=0, size , s;
while(fgets(str,400,fp)!=NULL){
type = 'd' ;
temp = str ;
size = temp.size();
s = size ;
x = 0 ;
y = 5 ;
while(size){
temp2 = temp.substr(x,y) ;
if(temp2=="11011")
type = 'd' ;
else if(temp2=="11111")
type = 'u' ;
for(i=0;i<j-1;i++){
if(temp2==b[i].bin){
if(type=='d')
cout << b[i].ds;
else if(type=='u')
cout << b[i].us;
}
}
if(s==x+6){
break ;
}
x += y ;
size-=5;
}
temp="";
strcpy(str,"");
cout << endl ;
}
fclose(fp) ;
return 0 ;
}
inp.txt 文件包含这四行
<T*O HNM=LRGIPCVEZDBSYFXAWJ UQK
>5@9 %,.+)4&80:;3"$?#6!/-2' 71(
100100110011000010011111101110000111110111101
001100001101111001001111100001001100010001100110111100000111
我无法找出问题,请帮助