C++ 问题3 大侠 再帮我一下
来源:百度知道 编辑:UC知道 时间:2024/06/05 11:08:52
Write a main program that illustrates the work of this function. If the given number is equal to the reversed number (e.g. 12321) the main program should display a message “it is a palindrome!”.
就是输入一些数字 输出的时候 把这些数字 倒置就行了 如果是1000 的话 就是1
一般的话 123 就是 321
#include<iostream>
#include<string>
using namespace std;
//Write a function that takes an arbitrary integer value and returns the number with its digits reversed.
//For example, given the number 12345 the function should return 54321.
//We assume that the reverse of 1000 can be 1 because leading zeros are omitted. Similarly, the reverse of 000123 is 321.
//Write a main program that illustrates the work of this function.
//If the given number is equal to the reversed number
// (e.g. 12321) the main program should display a message “it is a palindrome!”.
void reverse(string &s)
{
int n_z=s.find_first_not_of('0');
int n_rz=s.find_last_not_of('0');
bool rev=true;
for(int i=0, j=s.length()-1;i<s.length()/2;i++,j--)
if(s[i]!=s[j] ) rev=false;
if(rev)
{
cout<<"it is a palindrome!"<<endl;
return;
}
fo