#2 27.12.08 18:13
Re: Помогите в С++ please=)
Код: cpp:
#include <iostream> #include <conio.h> // для _getch() #include <string> #include <vector> #include <algorithm> using namespace std; //здесь фамилии естессно в DOS-кодировке string initial = "Петров Иванов Сидоров"; vector<string> s; vector<string> split(const string &s, const char *by = " ") { vector<string> res; int i, j; int n = s.size(); for (i = 0; i <= n; i = j + 1) { for (j = i; j < n && strchr(by, s[j]) == NULL;) j++; res.push_back(s.substr(i, j-i)); } return res; } int main() { cout << "Initial string: " << initial << endl; s = split(initial); //здесь происходит сортировка sort(s.begin(),s.end()); initial = ""; for (int i=0; i<s.size(); i++) { initial += s[i]+" "; } cout << "Final string: " << initial << endl; _getch(); return 0; }
Исправлено drug_detei (27.12.08 18:30)
Offline

