Solving BRCKTS on spoj
Solving BRCKTS on spoj
我正在尝试 http://www.spoj.com/problems/BRCKTS/,我得到了逻辑,但这在输入字符串时给出了分割错误。我认为问题在于在数组中插入字符,无法弄清楚。
int main() {
int t = 10;
int l = 1;
do{
int length_bracket;
char d;
cin>>length_bracket;
vector<char> word;
string output;
for( int i =0; i<length_bracket; i++) {
cin.get(d);
word.push_back(d);
}
int num_operations;
cin>>num_operations;
do{
int n;
cin>>n;
if(n == 0) {
if(word[0] == ')' || word[length_bracket] == '(') {
output = output + "NO" + 'n';
}
else {
int l1 = 0; int l2 = 0;
for(int i=0; i<length_bracket; i++) {
if(word[i] == ')') {
l1 = l1+1;
}
else {
l2 = l2+1;
}
}
if(l1 == l2 && l1 != 0 && l2 != 0 ) {
output = output + "YES" + 'n';
}
else {
output = output + "NO" + 'n';
}
}
}
else {
if(word[n-1] == '(')
word[n-1] = ')';
else
word[n-1] = '(';
}
num_operations--;
}while(num_operations);
cout<<"Test"<<l<<endl;
l++;
cout<<output;
t--;
}while(t);
return 0;
}
只是简单地浏览了一下代码,我看到您正在访问word[length_bracket]
但word
只包含length_bracket
个字符,因此您应该检查word[length_bracket-1]
。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 循环挂起迭代的 std::擦除 on std::list
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- std::bind on statd::array 的运算符 []
- 您将如何连接"on the fly"文本+整数并将其传递给函数?
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- VS2019 - Sudo Remote Debugging on Linux with Cmake project
- C++ library with Tensorflow on Android
- SFML 交叉编译 for Windows on Linux.
- How to recover system gcc compiler on centos 6
- Cmake with Flex/Bison on windows
- 按原样保存用户输入 - Ruby on Rails
- OpenAL C++ on Linux
- SPOJ 上的主生成器 PRIME1
- Boost::process on Windows - with MinGW?
- CMake on FindOpenGL.cmake 中的错误,当使用导入的目标 OpenGL::GLU?
- Utilization of atomic_flag on C++
- 为什么我得到这个代码的SIGABRT?( PRIME1 on SPOJ ).
- Solving BRCKTS on spoj