我个人认为难...我都郁闷了...
/*---------------------------------------------------------------------------
File name: 5=space.cpp
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 8/22/2007 12:57:23
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
Problem statement:
---------------------------------------------------------------------------
http://bbs.bc-cn.net/viewthread.php?tid=164729
输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。然后对这些分隔的数排序,有小到大排.
Sample output:
---------------------------------------------------------------------------
555123554758955555
555123554758955555
47 89 123
Press any key to continue . . .
12345678
12345678
678 1234
Press any key to continue . . .
0012350046700
0012350046700
123 46700
Press any key to continue . . .
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{
string s;
int i;
vector<int> vi;
istringstream iss;
// get input
getline(cin, s);
cout<<s<<endl;
// replace '5' by ' '
for(i=0; i<s.size(); ++i)
{
if(s[i]=='5')
{
s[i]=' ';
}
}
// break up numbers
iss.str(s);
while(iss>>i)
{
vi.push_back(i);
}
// sort
sort(vi.begin(), vi.end());
// print
for(vector<int>::const_iterator it=vi.begin(); it!=vi.end(); ++it)
cout<<*it<<" ";
cout<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{
string s;
int i;
vector<int> vi;
istringstream iss;
// get input
getline(cin, s); //让你输入一行数字,并存放在字符串s中
cout<<s<<endl; //在屏幕上输出字符串s
// replace '5' by ' '
for(i=0; i<s.size(); ++i)
{
if(s[i]=='5')
{
s[i]=' ';
}
}
// break up numbers
iss.str(s);
while(iss>>i)
{
vi.push_back(i);
}
// sort
sort(vi.begin(), vi.end());
// print
for(vector<int>::const_iterator it=vi.begin(); it!=vi.end(); ++it)
cout<<*it<<" ";
cout<<endl;
return 0;
}