题目大体要求字母不区分大小写,数字与字母不进行比较,输入只可能是字母和数字组成的串,比较指定长度以内的字符
//字母不区分大小写,字母与数字不比较
strncmp(const *char s1, const char* s2, int n){
int len=0;
while(len<n)
{
if(*s1=='\0')
{
if(*s2!='\0')
return -1;
else return 0;
}
if(*s2=='\0')
{
if(*s1!='\0')
return 1;
else return 0;
}
if(('a'<=*s1<='z'||'A'<=*s1<='Z')&&('a'<=*s2<='z'||'A'<=*s2<='Z'))
{
if(*s1==*s2)
{
s1++;
s2++;
len++;
}else
if(*s1<*s2)
{
if(*s1+26==*s2)
{
s1++;
s2++;
}
else
return -1;
}else
{
if(*s1==*s2+26)
{
s1++;
s2++;
}
else
return 1;
}
}else
if(!('a'<=*s1<='z'||'A'<=*s1<='Z')&&!('a'<=*s2<='z'||'A'<=*s2<='Z'))
{
if(*s1>*s2)
return 1;
else if(*s1<*s2)
return -1;
else
{
s1++;
s2++;
len++;
}
}
else
{
s1++;
s2++;
len++;
}
}
return 0;
}