#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
void sort(vector<int> &goal);
int main()
{
string line;
vector<int> goal;
vector<int>::iterator iter;
ifstream in("in.txt");
while(getline(in, line))
{
if(line.substr(0, 8) == "ÓïÎijɼ¨")
{
goal.push_back(atoi((line.substr(10, line.size() - 10)).c_str()));
}
}
sort(goal);
for(iter = goal.begin(); iter != goal.end(); iter++)
{
cout << "ÓïÎijɼ¨£º" << *iter << endl;
}
return 0;
}
void sort(vector<int> &goal)
{
vector<int>::iterator iter1;
vector<int>::iterator iter2;
int temp;
for(iter1 = goal.begin(); iter1 != goal.end(); iter1++)
{
for(iter2 = goal.begin(); iter2 != goal.begin()+(goal.end()-iter1-1); iter2++)
{
if(*iter2 > *(iter2+1))
{
temp = *iter2;
*iter2 = *(iter2+1);
*(iter2+1) = temp;
}
}
}
}
补充回答:
姓名:zhangsan
年龄:19
语文成绩:89
姓名:lisi
年龄:21
语文成绩:75
姓名:zhangsan
年龄:19
语文成绩:93
姓名:lisi
年龄:21
语文成绩:77
姓名:zhangsan
年龄:19
语文成绩:21
姓名:lisi
年龄:21
语文成绩:45
这是我测试用的文件,文件名in.txt
这是运行结果: