c语言发送短信,C语言,短信号码的提取。该如何解决

C语言,短信号码的提取。

Input

第一行有个整数n(1≤n≤1000)表示测试用例的个数。其后的每一行中有一条短信,每一条短信中只包含字母、数字、空格、标点符号,没有回车换行符,短信的长度不超过400个英文字符。

Output

将每条短信中的电话号码提取出来。每个号码占一行。如果该短信中没有电话号码,请输出“no phone numbers!” 每个测试用例的输出之间用一个空行隔开。

Sample Input

2

Mr Zhang's home phone is 073112345678, and his office phone is 87654321, his mobile phone is 13812345678

Sorry, I don't have his any phone numbers!

Sample Output

073112345678

87654321

13812345678

no phone numbers!

下面是我写的代码,但是提示答案错误,求好心人给我解决一下,谢谢了。

#include

#include

int main()

{

int n,i,r,t,j;

char s[800];

scanf("%d",&n);

getchar();

for(i=0;i

{

r=1;

gets(s);

t=strlen(s);

for(j=0;j

{

if('0'<=s[j] && s[j]<='9')

{

printf("%c",s[j]);

r=0;

}

else

{

if('0'<=s[j-1] && s[j-1]<='9')

{

printf("\n");

if(j+1!=t)

printf("\n");

}

}

}

if(r!=0)

{

printf("no phone numbers!\n");

}

if('0'<=s[t-1] && s[t-1]<='9')

printf("\n");

}

return 0;

}

------解决思路----------------------

#include

#include

int main()

{

int n,i,r,t,j;

char s[800];

scanf("%d",&n);

getchar();

for(i=0;i

{

r=1;

gets(s);

t=strlen(s);

for(j=0;j

{

if('0'<=s[j] && s[j]<='9')

{

printf("%c",s[j]);

r=0;

}

else

{

if('0'<=s[j-1] && s[j-1]<='9')

{

//printf("\n");

if(j+1!=t)

printf("\n");

}

}

}

if(r!=0)

{

printf("no phone numbers!\n");

}

if('0'<=s[t-1] && s[t-1]<='9')

printf("\n");

}

getchar();

return 0;

}题目貌似不清楚 phone1213123  这样提取出1213123算电话号码吗?  楼主方法是把字符串中数字提取出来 貌似有点小错误:多了个printf("\n");

------解决思路----------------------

自己再修改下

#include

#include

int main()

{

int n,i,r,t,j,count1,count2=0;

char s[800];

char (*p)[800];

scanf("%d",&n);

getchar();

p=(char *)malloc(n*800);

for(i=0,count1=0;i

{

r=1;

gets(s);

t=strlen(s);

for(j=0;j

{

if('0'<=s[j] && s[j]<='9')

{

p[count1][count2++]=s[j];

r=0;

if(j+1==t)

{

p[count1][count2]='\0';

count2=0;

count1++;

}

}

else

{

if('0'<=s[j-1] && s[j-1]<='9')

{

p[count1][count2]='\0';

count2=0;

count1++;

}

}

}

if(r!=0)

{

printf("no phone numbers!\n");

}

p[count1][count2]='\0';

}

for(i=0;i

{

printf("%s\n",p[i]);

}

return 0;

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值