<span style="font-family:KaiTi_GB2312;">代码:</span>
#include<stdio.h>
#include<string.h>
bool BE(char str[]) //开头为 '+' 返回1
{
if(str[0]=='+')
return 1;
return 0;
}
bool _86(char str[],int len) //是否以86 开头
{
if(BE(str))
{
if(str[1]=='8'&&str[2]=='6')
return 1;
else
return 0;
}
else
{
if(str[0]=='8'&&str[1]=='6')
return 1;
else
return 0;
}
}
int Len(char str[],int len)
{
int i,k=0;
for(i=0;i<len;++i)
{
if(str[i]>='0'&&str[i]<='9')
k++;
}
return k;
}
bool _FSZ(char str[],int len) //推断是否含非数字,是返回1;
{
int i;
if(BE(str))
for(i=1;i<len;++i)
{
if(str[i]!='-'&&!(str[i]>='0'&&str[i]<='9'))
return 1;
}
else
{
for(i=0;i<len;++i)
{
if(str[i]!='-'&&!(str[i]>='0'&&str[i]<='9'))
return 1;
}
}
return 0;
}
int MAIN()
{
char str[20];
gets(str);
int len=strlen(str);
switch(len)
{
case 13:if(_86(str,len)) return 0;//else break;
case 14:if(_86(str,len))if(BE(str)||str[2]=='-') return 0;
case 15:if(_86(str,len))if(BE(str)&&str[3]=='-') return 0;
case 17:if(_86(str,len))if(BE(str)&&str[3]=='-'&&str[7]=='-'&&str[12]=='-') return 0;
}
if(Len(str,len)!=13) // 长度不合格
return 1;
else
{
if(_FSZ(str,len))
return 2;
else
{
if(_86(str,len))
return 4;
else
return 3;
}
}
}
int main()
{
while(1)
printf("%d\n",MAIN());
return 0;
}原文:http://www.cnblogs.com/mthoutai/p/7359446.html