努力ing
你浪费的今天是昨天死去的人所渴望的明天!!!

学会用函数strtok,功能:函数返回字符串str1中紧接“标记”的部分的指针, 字符串str2是作为标记的分隔符。如果分隔标记没有找到,函数返回NULL。为了将字符串转换成标记,第一次调用str1 指向作为标记的分隔符。之后所以的调用str1 都应为NULL。

例如:

    char str[] = "now # is the time for all # good men to come to the # aid of their country";
    char delims[] = "#";
    char *result = NULL

result = strtok( str, delims )
  while( result != NULL ) {
        printf( "result is \"%s\"\n", result );
         result = strtok( NULL, delims );
    }

以上代码的运行结果是:

    result is "now "
    result is " is the time for all "
    result is " good men to come to the "
    result is " aid of their country"

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
 char str[1005];
 char *p;
 while(cin>>str)
 {
  int a[1005];
  int i,t=0;
  p=strtok(str,"5");
  while(p)
  {
   a[t++]=atoi(p);           //将字符串转化为整型
 //  cout<<p<<' ';
   p=strtok(NULL,"5");
  }
  sort(a,a+t);
  for(i=0;i<t;i++){
   cout<<a[i];
   if(i==t-1) cout<<endl;
   else cout<<' ';
  }
 }
 return 0;
}

posted on 2013-05-07 13:26  努力ing  阅读(104)  评论(0)    收藏  举报