主题:判断对称数
yuhua
[专家分:1730] 发布于 2006-03-29 14:03:00
用c语言
不能用任何系统函数
那位高手给个简单的算法
我是用最笨的方法弄得
对称数
11
1221
123321
之类的
回复列表 (共21个回复)
11 楼
freeeerf [专家分:5440] 发布于 2007-02-15 14:22:00
我们大一的C语言考试时就有这样的题,后来想到可以用sprintf()函数,把整数放在数组里,再从两头往中间比较,或者读取整数时直接用gets()。
12 楼
gaolubing [专家分:20] 发布于 2007-03-29 08:36:00
都是高手啊
最简单的方法尽然没人想到
晕
入栈和出栈
13 楼
江南孤峰 [专家分:1520] 发布于 2007-03-29 22:06:00
#include <stdio.h>
#define MAX 100
int main(){
char str[MAX];
int i,j;
scanf("%s",str);
for(i = 0; str[i]; i ++)
; /* 这里 i = strlen(str); 多好 */
for(j = 0,i --; i > j; i --,j ++)
if(str[i] != str[j]){
i = -1;
break;
}
if(i != -1)
printf("是回文\n");
else
printf("不是回文\n");
return 0;
}
// 还是用了系统函数 printf(),scanf()
14 楼
orangepigmm [专家分:10] 发布于 2007-04-18 09:11:00
问个不专业问题 DWORD 是什么数据类型啊
15 楼
bpttc [专家分:8790] 发布于 2007-04-18 11:26:00
[quote]问个不专业问题 DWORD 是什么数据类型啊[/quote]
double word 双字
16 楼
编程新手007 [专家分:270] 发布于 2007-04-19 16:46:00
楼上这个方法比较特别,细化一下,可以,效率也不错
17 楼
多C多漂亮 [专家分:0] 发布于 2007-06-05 12:46:00
main()
{
int i,j;
printf("please input:");
scanf("%d\n",&i)
for ^
18 楼
朋友,你还好吗? [专家分:40] 发布于 2007-06-06 12:51:00
用栈,还不错!
19 楼
xust [专家分:10] 发布于 2007-11-04 23:15:00
同意楼上的 用栈
20 楼
xust [专家分:10] 发布于 2007-11-04 23:18:00
我是个初学者 这是用栈编的 可能有些烦琐 不过可以执行
我QQ:271150521 有意向的加我哦 大家交流交流
#include<iostream.h>
#define maxsize 100
typedef struct
{
char data[maxsize];
int top;
}seqstack;
seqstack *init_seqstack()
{
seqstack *l;
l=new(seqstack);
l->top=-1;
return l;
}
int empty_seqstack(seqstack *s)
{
if(s->top==-1)return 1;
else return 0;
}
int push_seqstack(seqstack *s,char x)
{
if(s->top==maxsize-1) return 0;
else
{
s->data[++s->top]=x;
return 1;
}
}
int pop_seqstack(seqstack *s,char *x)
{
if(empty_seqstack(s)) return 0;
else
{
*x=s->data[s->top--];
return 1;
}
}
int top_seqstack(seqstack *s)
{
if(empty_seqstack(s)) return 0;
else return(s->data[s->top]);
}
void main()
{
seqstack *s,*a;
s=init_seqstack();
a=init_seqstack();
char x;
int i=0,j=0,k=0,l=0;
int flag=1;
cout<<"input $ to end it"<<endl;
cout<<"input:";
while(flag)
{
cin>>x;
if(x!='$')
{
push_seqstack(s,x);
cout<<x;
j++;
}
else
flag=0;
}
cout<<endl;
cout<<"input "<<j<<" numbers"<<endl;
if(j%2==0)
{
while(l<j/2)
{
pop_seqstack(s,&x);
push_seqstack(a,x);
l++;
}
cout<<endl;
while(!empty_seqstack(s)&&!empty_seqstack(a))
{
char m,n;
pop_seqstack(s,&m);
pop_seqstack(a,&n);
if(m==n)
{
k++;
}
else
break;
}
if(k==j/2)
cout<<"回文"<<endl;
else
cout<<"不回文"<<endl;
}
else
{
while(l<j/2)
{
pop_seqstack(s,&x);
push_seqstack(a,x);
l++;
}
cout<<endl;
pop_seqstack(s,&x);
while(!empty_seqstack(s)&&!empty_seqstack(a))
{
char m,n;
pop_seqstack(s,&m);
pop_seqstack(a,&n);
if(m==n)
{
k++;
}
else
break;
}
if(k==j/2)
cout<<"回文"<<endl;
else
cout<<"不回文"<<endl;
}
}
我来回复