c++ - 试图刷新我的编码。回文练习给我一个问题。谷歌搜索了我的错误,但无法修复它。
问题描述
我正在做一个 c++ 练习,老实说,关于字符串的知识有点模糊,可能是为什么这不起作用。我在语法上忘记了很多,但总的来说我对 OOP 有很好的基本理解。只是想回到事物的摇摆中。我也知道我的一致性与 std:: 很奇怪,然后在像 cin haha 这样的地方省略了它。就是胡闹。谢谢你的帮助。
#include <iostream>
#include <string>
std::string reverse(std::string s);
using namespace std;
int main(){
std::string s;
cin>>s;
std::string n = reverse(s);
if(n == s){
std::cout<<"plindrome"endl;
}
}
string reverse(string s){
int n = s.length();
for(int i = 0; i<n/2; i++){
swap(s[i], s[n-1-1])
}
return s;
}
解决方案
swap(s[i], s[n-1-1])
仔细看第二个论点。
推荐阅读
- c - C中多维数组的存储顺序
- java - Spring Boot 批处理中的 StoredProcedureItemReader
- php - 如何基于一个文件处理多个文件?(GIT)
- braintree - Braintree/PayPal 版本 3 升级问题
- soap - Yii 1.1 - SoapServer::SoapServer(url): 无法打开流
- c# - TryParse() 短路和输出变量可靠吗?
- java - 使用servelt java将html日期值存储到mysql数据库时出现NullPointerException
- jquery - 如何为 HTML 中类的每个元素分配一个序列号?
- c - C 中的结构中的 int64_t 值溢出
- javascript - React Route 未在生产中显示组件