C++函数编程,如果一个整数逆序后得到的数值和原数值相同,则称之为幸运数。输入一个整数N
C++函数编程,如果一个整数逆序后得到的数值和原数值相同,则称之为幸运数。输入一个整数NN<100000判断是否为幸运数,是的话输出yes,否则为no...
C++函数编程,如果一个整数逆序后得到的数值和原数值相同,则称之为幸运数。输入一个整数NN<100000判断是否为幸运数,是的话输出yes,否则为no
展开
3个回答
展开全部
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool is_lucky_num (string s)
{
string s_rev = s;
reverse(s_rev.begin(), s_rev.end());
if (s_rev == s)
return true;
return false;
}
int main()
{
string s;
cin>>s;
if (is_lucky_num(s))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}
g++编译通过,望采纳~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
void isLuky(long n){
long a=0;
string strA;
string strB;
ostringstream s1;
ostringstream s2;
s1<<n;
strA=s1.str();
while(n){
a=n%10;
s2<<a;
strB=s2.str();
n=n/10;
}
if(strA.compare(strB)==0){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}
void main(){
long num;
cout<<"请输入一个小于100000的数:";
cin>>num;
while(num>100000){
if(num<=100000){
break;
}
cout<<"必须输入一个小于100000的数!\n"<<endl;
cout<<"请输入一个小于100000的数:";
cin>>num;
}
isLuky(num);
}
#include <sstream>
#include <string>
using namespace std;
void isLuky(long n){
long a=0;
string strA;
string strB;
ostringstream s1;
ostringstream s2;
s1<<n;
strA=s1.str();
while(n){
a=n%10;
s2<<a;
strB=s2.str();
n=n/10;
}
if(strA.compare(strB)==0){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}
void main(){
long num;
cout<<"请输入一个小于100000的数:";
cin>>num;
while(num>100000){
if(num<=100000){
break;
}
cout<<"必须输入一个小于100000的数!\n"<<endl;
cout<<"请输入一个小于100000的数:";
cin>>num;
}
isLuky(num);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
if(10000<=N&&N<=99999){
if(N/10000==N%10&&(N%10000)/1000==(N/10)%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(1000<=N&&N<=9999){
if(N/1000==N%10&&(N%1000)/100==(N/10)%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(100<=N&&N<=999){
if(N/100==N%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(10<=N&&N<=99){
if(N/10==N%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(0<=N&&N<=9)
cout<<"yes"<<endl;
}
}
}
}
return 0;
}
using namespace std;
int main()
{
int N;
cin>>N;
if(10000<=N&&N<=99999){
if(N/10000==N%10&&(N%10000)/1000==(N/10)%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(1000<=N&&N<=9999){
if(N/1000==N%10&&(N%1000)/100==(N/10)%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(100<=N&&N<=999){
if(N/100==N%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(10<=N&&N<=99){
if(N/10==N%10)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else{
if(0<=N&&N<=9)
cout<<"yes"<<endl;
}
}
}
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询