@igorrr37
1812 / 1430 / 214
Регистрация: 21.12.2010
Сообщений: 2,331
|
02.03.2014, 12:02
|
|
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
| #include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cctype>
#include <vector>
#include <complex>
int main()
{
std::ifstream ifs("in.txt");
if(ifs.is_open())
{
std::string str;
std::stringstream sstr;
std::vector<std::vector<std::complex<double> > > mtx;
double re, im;
for(int j = 0; std::getline(ifs, str); ++j)
{
std::string::size_type i, len = str.size();
for(i = 0; i < len; ++i)
{
if(!(isdigit(str[i]) || '-' == str[i] || '.' == str[i]))
str[i] = ' ';
}
mtx.push_back(std::vector<std::complex<double> >());
sstr.clear();
sstr.str(str);
while(sstr >> re >> im)
{
mtx[j].push_back(std::complex<double>(re, im));
}
mtx[j].push_back(std::complex<double>(re, 0));
}
for(std::vector<std::vector<std::complex<double> > >::const_iterator ib = mtx.begin(); ib != mtx.end(); ++ib)
{
for(std::vector<std::complex<double> >::const_iterator ib1 = ib->begin(); ib1 != ib->end(); ++ib1)
{
std::cout << *ib1 << " ";
}
std::cout << '\n';
}
ifs.close();
}
else
std::cerr << "Unable to open input file\n";
return 0;
} |
|
Добавлено через 38 минут
Кликните здесь для просмотра всего текста
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
| #include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cctype>
#include <vector>
#include <complex>
int main()
{
std::ifstream ifs("in.txt");
if(ifs.is_open())
{
std::string str;
std::stringstream sstr;
std::vector<std::vector<std::complex<double> > > mtx;
double re, im;
while(std::getline(ifs, str))
{
std::replace_if(str.begin(), str.end(), [](char c){return !(isdigit(c) || '.' == c || '-' == c);}, ' ');
mtx.emplace_back(decltype(mtx)::value_type());
sstr.clear();
sstr.str(str);
while(sstr >> re >> im)
{
mtx.back().emplace_back(std::complex<double>(re, im));
}
mtx.back().emplace_back(std::complex<double>(re, 0));
}
for(auto const& val : mtx)
{
for(auto const& val1 : val)
{
std::cout << val1 << " ";
}
std::cout << '\n';
}
ifs.close();
}
else
std::cerr << "Unable to open input file\n";
return 0;
} |
|
0
|