要求不要用字符串比较函数!
[此贴子已经被作者于2006-11-28 20:36:23编辑过]
#include<stdio.h>
void one(char a,char b,char c);
void two(char a,char b,char c);
main()
{
char a,b,c;
printf("用空格隔空\n");
scanf("%c %c %c",&a,&b,&c);
one(a,b,c);
two(a,b,c);
}
void one(char a,char b,char c)
{printf("%c\n",a>=b?a>=c?a:c:b>=c?b:c);}
void two(char a,char b,char c)
{
if(a>=b)
if(a>=c)
printf("%c",a);
else
printf("%c",c);
else
if(b>=c)
printf("%c",b);
else
printf("%c",c);
}
[此贴子已经被作者于2006-11-30 21:26:08编辑过]
比较长度 和字典序就可以了
#include<stdio.h>
#include<string.h>
void main()
{
char *s1=\"chinese\",*s2=\"futures\",*s3=\"Chinese\",*s=\"same\";
//scanf(\"%s,%s,%s\",s1,s2,s3);
char *p=s;
p=strlen(s1)>strlen(s2)?
(strlen(s1)>strlen(s3)?//true
s1:(strlen(s1)==strlen(s3)?
s:s3))
:(strlen(s2)>strlen(s3)?//flase
s2:(strlen(s2)==strlen(s3)?
s:s3));if(p==s)
{
for(int i=0;i<strlen(p);)
{
if(s1[i]>s2[i])
{if(s1[i]>s3[i]) {printf(\"max string is %s\",s1);break;}
else if(s1[i]==s3[i]) i++;
else if(s1[i]<s3[i]) {printf(\"max string is %s\",s3);break;}
}
else if(s1[i]==s2[i]) i++;
else if(s2[i]>s3[i]) {printf(\"max string is %s\",s2);break;}
else if(s2[i]==s3[i]) i++;}
}
else printf(\"max string is %s\",p);
}