采用標准輸入輸出:
輸入:12&3 34*133^3131 13031*
輸出:12 3 34 133 3131 13031
思路,先將整個輸入存進一個字符串,再解析字符串,這樣運行速度會快些。
1 int GetNum(const char* str,int* num) //輸入:str---字符串指針,num---要保存數字的數組指針 返回:數字個數 2 { 3 int len=strlen(str); 4 int index=0; 5 int t; 6 for(int i=0;i<len;i++) 7 { 8 while(!(str[i]>'0'&&str[i]<'9')) 9 { 10 i++; 11 } 12 while(str[i]>='0'&&str[i]<'9') 13 { 14 t=str[i]-'0'; 15 num[index]=num[index]*10+t; 16 i++; 17 } 18 index++; 19 } 20 return index; 21 }