문제를 해결하였다고 생각하여 제출했는데 런타임 에러가 뜨더군요.
RTE (SIGABRT: program aborted, probably assertion fail)
RTE (SIGSEGV: segmentation fault, probably incorrect memory access or stack overflow)
라는 에러가 발생하였습니다. 같은 코드를 여러번 제출하였는데 저 두가지 에러가 발생하더군요.
코드는 다음과 같습니다.
~~~ c++
#include
#include
#include
#include
using namespace std;
int start[30];
int fin[30];
char firstword,finishword;
int size;
list str[30];
void cal(int status){
string now;
int index;
if(status == 1){
for(int i=0;i<26;i++){
if(start[i] > 0){
now = "";
now += str[i].front();
str[i].pop_front();
break;
}
}
}
else{
now = str[firstword-'a'].front();
str[firstword-'a'].pop_front();
}
size --;
printf("%s ",now.c_str());
while(size--){
index = now[now.length()-1] - 'a';
now = str[index].front();
str[index].pop_front();
printf("%s ",now.c_str());
}
printf("\n");
luku756
[[problem:WORDCHAIN]]
문제를 해결하였다고 생각하여 제출했는데 런타임 에러가 뜨더군요.
RTE (SIGABRT: program aborted, probably assertion fail)
RTE (SIGSEGV: segmentation fault, probably incorrect memory access or stack overflow)
라는 에러가 발생하였습니다. 같은 코드를 여러번 제출하였는데 저 두가지 에러가 발생하더군요.
코드는 다음과 같습니다.
~~~ c++
#include
#include
#include
#include
using namespace std;
int start[30];
int fin[30];
char firstword,finishword;
int size;
list str[30];
void cal(int status){
string now;
int index;
if(status == 1){
for(int i=0;i<26;i++){
if(start[i] > 0){
now = "";
now += str[i].front();
str[i].pop_front();
break;
}
}
}
else{
now = str[firstword-'a'].front();
str[firstword-'a'].pop_front();
}
size --;
printf("%s ",now.c_str());
}
int possible(){
int onfirst = 0, onfinish=0;
for(int i=0;i<26;i++){
if(start[i] != fin[i]){
if(start[i] - fin[i] == 1){
if(onfirst == 1)
return -1;
onfirst=1;
firstword='a'+i;
}
else if(start[i] - fin[i] == -1){
if(onfinish == 1)
return -1;
onfinish=1;
finishword='a'+i;
}
else
return -1;
}
int main(){
int TC,num,posi;
string tmpstr;
char tmp[130];
}
~~~
재귀가 아니니 스택 오버플로우는 아니라 생각되어 나름대로의 워스트 케이스라고 생각되는 (한군데 데이터가 과도하게 집중된 경우) 50회, 100번의 aaaaaaaaaa 을 넣어봤는데 문제 없이 잘 작동하였습니다.
무엇이 문제인지 알려주시면 감사하겠습니다 ㅠㅠ
혹 list나 string의 일부 기능이 우분투 환경에서는 동작하지 않는다던가 하는 부분이 있나요? 코딩은 vs2010으로 진행하였습니다.
11년 전