提取電話號碼
阿新 • • 發佈:2019-04-21
zhang style sorry num font i++ any lse mobile 提取電話號碼
Sorry, I don‘t have his any phone numbers!
提取電話號碼
提取一條短信裏所有的電話號碼,電話號碼之間換行打印,短信的內容由用戶輸入。
輸入
第一行有個整數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 }
提取電話號碼