noi 提取数字串按数值排序
原题链接:点我转移
#include<bits/stdc++.h> using namespace std; int main() { char str[400]; while(cin >> str) { int num[200]={0}; int flag=0,coun=0; for (int i = 0; str[i] != '\0'; i++) { if (flag == 0 && str[i] >= '0'&&str[i] <= '9') { coun++; num[coun] = str[i] - '0'; flag = 1; continue; } if (flag == 1 && str[i] >= '0'&&str[i] <= '9') { num[coun] = num[coun] * 10 + str[i] - '0'; continue; } if(flag==1&&( str[i] < '0'||str[i] > '9')) flag = 0; } if (coun == 0) cout << "0" << endl; else { sort(num+1,num+coun+1); for (int i = 1; i <= coun-1; i++) cout << num[i]<<","; cout << num[coun]<<endl; } } return 0; }