提取电话号码

提取电话号码
提取一条短信里所有的电话号码,电话号码之间换行打印,短信的内容由用户输入。

输入

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

输出

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

输入用例
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!

输出用例
073112345678
87654321
13812345678

no phone numbers!

 1 #include<stdio.h>
 2 
 3 #include<string.h>
 4 
 5 int main() 
 6 
 7 {
 8 
 9     int n,i,r,t,j;
10 
11     char s[1000];
12 
13     scanf("%d",&n);
14 
15     getchar();
16 
17     for(i=0;i<n;i++)
18 
19     {
20 
21         r=1;
22 
23         gets(s);
24 
25         t=strlen(s);
26 
27         for(j=0;j<t;j++)
28 
29         {
30 
31             if('0'<=s[j] && s[j]<='9')
32 
33             {
34 
35                 printf("%c",s[j]);
36 
37                 r=0;
38 
39             }
40 
41             else 
42 
43             {
44 
45                 if('0'<=s[j-1] && s[j-1]<='9')
46 
47                 {
48                     if(j+1!=t)
49 
50                         printf("\n");
51 
52                 }
53 
54             }
55 
56         }
57 
58         if(r!=0)
59 
60         {
61 
62             printf("no phone numbers!\n");
63 
64         }
65         printf ("\n");
66 
67         if('0'<=s[t-1] && s[t-1]<='9')
68 
69             printf("\n");
70 
71     }
72 
73     getchar();
74 
75     return 0; 
76 
77 }

猜你喜欢

转载自www.cnblogs.com/zyxdjyd/p/10746005.html