标签:排序 \n return mis cout 数据 输出 turn out
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 75271 Accepted Submission(s): 23079
把字符串中5当成空格,然后把那些分割开的数字排序输出
使用STL的strtok和sscanf会变得很简单
strtok每次返回一个隔开的字符串,sscanf把这个字符串赋给int数组
最后用sort给int数组排一下序
strtok可以去这里看http://www.cplusplus.com/reference/cstring/strtok/
sscanf http://www.cplusplus.com/reference/cstdio/sscanf/
1 #include<bits/stdc++.h> 2 using namespace std; 3 char s[1005]; 4 int b[1005]; 5 int main() 6 { 7 while(~scanf("%s",s)) 8 { 9 char *p; 10 int k = 0; 11 p = strtok(s,"5"); 12 //cout<<p<<endl; 13 while(p != NULL) 14 { 15 sscanf(p,"%d",&b[k++]); 16 p = strtok(NULL,"5"); 17 // cout<<p<<endl; 18 } 19 sort(b,b+k); 20 printf("%d",b[0]); 21 for(int i = 1; i < k; i++) 22 printf(" %d",b[i]); 23 printf("\n"); 24 } 25 return 0; 26 }
hdu1106 排序(字符串分割,strtok+sscanf)
标签:排序 \n return mis cout 数据 输出 turn out
原文地址:https://www.cnblogs.com/fqfzs/p/9959232.html