检查两个彼此相邻的两个下划线
checking for two underscores next to each other
我的代码应该检查两个下一个下一个下一个彼此,在字符串的开头还是在字符串的末尾以及更多其他规则.....问题是代码时在整个字符串中找到2个强调,它打印了Chyba,但不应该。只有在找到类似abc__abc
的东西时,它才能打印Chyba,但它像abc_abc_abc
>> Chyba ...有什么解决方案吗?
void Convert(string input){
string output = "";
string flag = "";
bool underscore = false;
bool uppercase = false;
if ( islower(input[0]) == false){
cout << "Chyba!" <<endl;
return;
}
for (int i=0; i < input.size(); i++){
if ( (isalpha( input[i] ) || (input[i]) == '_') == false){
cout << "Chyba!" <<endl;
return;
}
if (islower(input[i])){
if (underscore){
underscore = false;
output += toupper(input[i]);
}
else
output += input[i];
}
else if (isupper(input[i])){
if (flag == "C" || uppercase){
cout << "Chyba!"<<endl;
return;
}
flag = "Java";
output += '_';
output += tolower(input[i]);
}
else if (input[i] == '_'){
if (flag == "Java" || underscore){
cout << "Chyba!" <<endl;
return;
}
flag = "C";
underscore = true;
}
}
for (int i=input.size()-1; i >=0; i--){
if (input[i] == '_'){
if (flag == "Java" || underscore){
cout << "Chybaaa!" <<endl;
return;
}
flag = "C";
underscore = true;
}
}
cout << output <<endl;
}
bool containsAdjacentUnderscores = std::search_n(begin(input), end(input), 2, '_') != end(input);
相关文章:
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 在什么情况下,两个堆栈分配的结构对象的 this 点指向同一个地址?
- 我有两棵二叉树.我想在不更改输入树的情况下深度复制两个二叉树的结果
- 在单元测试中,如何在不使用 operator== 的情况下比较两个对象,这可能会错过新成员?
- 无法使用两个包装不同下一层的ssl_stream编译代码
- STL:在没有输出的情况下处理两个集合
- 如何在不创建新配置的情况下对两个不同解决方案使用的一个项目使用不同的 #defines
- 在不使用 * 和 / 运算符的情况下将两个浮点数相乘和除以
- 如何在不将其拆分为两个嵌套循环的情况下打印整个形状?
- 在没有额外代码的情况下链接两个独立类的最通用方法是什么?
- 通过两个下标访问数组成员
- 如何合并两个双重链接列表(访问下一个链接)
- 重命名两个目录中的文件名,如果它们之间的某些字符匹配 - 矢量下标超出范围
- 在没有返回值优化的情况下将两个对象加在一起时,将创建多少个临时对象
- 如何在没有 c++ 中的数组/算法的情况下对两个条件的字符串进行排序
- 在这种情况下,有没有办法用单个解决方案替换两个仅在类型上不同的相似函数?
- 如何在没有复制赋值运算符的情况下交换两个对象
- 有没有办法在不使用两个 for 循环的情况下迭代两个容器
- 检查两个彼此相邻的两个下划线
- 在Hpux C程序中__(两个下划线)代表什么?