整数是否为对称数(华为的比试题目)

stupidfish2004 2005-03-18 04:46:47
华为的比试题目,大家来看看!
...全文
1088 38 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
visual4825 2005-03-21
  • 打赏
  • 举报
回复
学习中
mythlee 2005-03-20
  • 打赏
  • 举报
回复
bool check_reverse(unsigned int x)
{
int d=0;
do {
if(d==x) return true;
else if(d==x/10) return true;
else {
d=d*10+x%10;
x=x/10;
}
}while(d<=x);
return false;
}
kingofvc 2005-03-20
  • 打赏
  • 举报
回复
1 转字符
2 字符反转
3 比较原字符
cxyol 2005-03-20
  • 打赏
  • 举报
回复
mark
huhaibin62003 2005-03-20
  • 打赏
  • 举报
回复
int dc(int n)
{
int m=0,v=n;
while(v>0){
m=m*10+v%10;
v/=10;
}
return (m==n);
}
阿明这一段就是C++(清华大学大学出版社)的例题吗 这么简单的题华为会出?!!
jronald 2005-03-20
  • 打赏
  • 举报
回复
CString s1;
cin>>s1;
CString s2(s1);
s2.MakeReverse();
if(s1==s2){
cout<<"yes"<<endl;
}
smartcomplier 2005-03-20
  • 打赏
  • 举报
回复
bool isSymmetryInt(int source)
{
char *temp = (char*)malloc(128*sizeof(char));
int len;
int i=0;
sprintf(temp,"%d",source);
if(*temp == '+'|| *temp == '-')
{
temp++;
}
len = (int)strlen(temp);
if(len==1)
{
return true;
}
while((*(temp+i)==*(temp+len-1-i))&&(i<len/2))
{
i++;
}
if(i==len/2)
{
return true;
}
free(temp);
return false;
}

随便贴一下......
feixiaofo 2005-03-20
  • 打赏
  • 举报
回复
本人大体简单的写了一下:
void main()
{
int num1,num2,m,n,k;
cout<<"please input a number:";
cin>>num1;
k=num1;
n=0;
num2=0;
while (m!=0)
{
m=k/10;
n=k%10;
num2=10*num2+n;
k=m;
}
if (num2==num1)
cout<<"此数是回文数。";
}
stupidfish2004 2005-03-20
  • 打赏
  • 举报
回复
谢谢各位指点,这次应聘以失败告终,不过学到不少东西!
inlin 2005-03-20
  • 打赏
  • 举报
回复
高手!
我学习中!
FandLR 2005-03-20
  • 打赏
  • 举报
回复
LoveCreatesBeauty(爱产生美)
is 高手啊,呵呵
llf_hust 2005-03-20
  • 打赏
  • 举报
回复
int Test(char *s, int start, int end)
{
if (s[start] != s[end])
return 0;
else if (end-start >2)
Test(s,start+1,end-1);
return 1;
}

flag = Test(s,0,strlen(s)-1);
if (flag == 1)
printf("Yes");
else
printf("No");
字符串版本
L_BOY 2005-03-20
  • 打赏
  • 举报
回复
不用字符也好做啊!
#include <iostream>
using namespace std;
void main()
{
int x,m=0,n;
cin >>x;
n=x;
while(n)
{
m=m*10+n%10;
n=n/10;
}
if(m==x)
cout <<"yes!"<<endl;
else
cout <<"no!"<<endl;
}
LoveCreatesBeauty 2005-03-20
  • 打赏
  • 举报
回复
another thing is that we shoud deal with different number system, for example:

i = 121;
j = symtrcnum(i, 10); //decimal

i = 0xa0a;
j = symtrcnum(i, 0x10); //hexadecimal

i = 0707;
j = symtrcnum(i, 010); //octal
LoveCreatesBeauty 2005-03-20
  • 打赏
  • 举报
回复
>喜欢“liem(阿明)”的程序,将数倒过来比较

His is really a good one, respond rapidly when job interview.
Perhaps no need to do so many loops.
LoveCreatesBeauty 2005-03-20
  • 打赏
  • 举报
回复
>12345678910111101987654321

constant too big

the maximum non-negative is defined in <limits.h>
ULONG_MAX Maximum value for a variable of type unsigned long. 4294967295 (0xffffffff)
LoveCreatesBeauty 2005-03-19
  • 打赏
  • 举报
回复
Estimate an integer if it's an symmetric number
http://www.cnblogs.com/lovecreatesbeauty/archive/2005/03/19/121510.html
FromNoWhere 2005-03-19
  • 打赏
  • 举报
回复
bool judgesym(int a)
{
//char strInt[32];
//itoa(a, strInt, 10);
//int length=strlen(strInt);
//for(int i=0, j=length-1; strInt[i]==strInt[j]&&i<=j; i++, j--);
//return (i-j)==2||(i-j)==1;
int tmpA=0, tmpB=0;

while((a/10)){
int tmpLoc=a;
while((tmpLoc/10)) tmpLoc/=10;
tmpA=tmpLoc;
tmpB=a%10;
if(tmpA!=tmpB)
return false;
a=(a/10)-(a%10);
}
return true;
}
pcboyxhy 2005-03-19
  • 打赏
  • 举报
回复
如果输入

12345678910111101987654321
yzkzero 2005-03-19
  • 打赏
  • 举报
回复
喜欢“liem(阿明)”的程序,将数倒过来比较
加载更多回复(18)

15,447

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧