@Haster
инженер-системотехник
111 / 110 / 2
Регистрация: 10.03.2009
Сообщений: 533
|
01.02.2012, 10:31
|
|
Первая задача:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| #include <iostream>
#include <conio.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
//
bool MySort (string str1, string str2)
{
return str1.compare(str2);
}
void main()
{
vector<string> words;
string input;
cout<<"Enter string: "<<endl;
getline(cin,input,'\n');
bool flag = true;
size_t pos = 0;
size_t pos_l = 0;
while (flag)
{
pos_l = input.find(' ',pos);
if (pos_l == string::npos)
{
string temp = input.substr(pos);
if (isalpha(temp[0]))
words.push_back(temp);
flag = false;
}
else
{
string temp = input.substr(pos, pos_l-pos);
if (isalpha(temp[0]))
words.push_back(temp);
pos = pos_l+1;
}
}
sort(words.begin(), words.end(), MySort);
for (int i = 0; i < words.size(); i++)
cout<<"word "<<i<<": "<<words[i]<<endl;
getch();
} |
|
1
|