我有一个3列的txt文件:"dd/mm/yyyy HH:MM:SS number(000.000)"
。大约有368个条目。如何在命令中删除向量中的重复值?
我想选择strings
,其中第三列的值是唯一的(第一次见面)。订单很重要。
在我的代码我在vector
(dtp
)读取文件,然后填充每个column
在vector
(data
,time
,pressure
)。然后我删除第3列的值,并得到this。
我的问题是如何添加第一和第二列与正确的指数,并得到this?
数据实例(冷杉的15个值):
26.07.2017 15:47:38 82.431
26.07.2017 16:47:46 83.431
26.07.2017 17:47:54 85.431
26.07.2017 18:48:02 84.431
26.07.2017 19:48:09 83.431
26.07.2017 20:48:17 83.431
26.07.2017 21:48:24 84.431
26.07.2017 22:48:32 83.431
26.07.2017 23:48:40 83.431
27.07.2017 00:48:48 84.431
27.07.2017 01:48:55 84.431
27.07.2017 02:49:03 84.431
27.07.2017 03:49:10 84.431
27.07.2017 04:49:19 84.431
27.07.2017 05:49:27 86.431
代码:
include <iostream>
include <fstream>
include <string>
include <algorithm>
include <iterator>
include <sstream>
include <vector>
include <cstring>
include <ctime>
using namespace std;
int main()
{
const clock_t start = clock();
system("mode con cols=50 lines=1000");
setlocale(LC_ALL, "Russian");
vector<string> dtp;
vector<string> data;
vector<string> time;
vector<double> pressure;
double num(0.0);
string line, tmp1, tmp2;
int len = 368;
int f, i, j, k;
ifstream file("data.txt");
while (!getline(file, line).eof())
dtp.push_back(line);
for (string &it : dtp)
{
{
istringstream isstr(it);
isstr >> tmp1;
data.push_back(tmp1);
}
{
istringstream isstr(it);
isstr >> tmp1 >> tmp2;
time.push_back(tmp2);
}
{
istringstream isstr(it);
isstr >> tmp1 >> tmp2 >> num;
pressure.push_back(num);
}
}
f = 0;
for (i = 0; i < len; i++)
{
for (j = i + 1; j < len; j++)
{
if (pressure[i] == pressure[j])
{
for (k = j; k < (len - 1); k++)
pressure[k] = pressure[k + 1];
len--;
j--;
f = 1;
}
}
}
if (f == 1)
{
for (i = 0; i < len; i++)
cout << pressure[i] << endl;
}
const double vremya = static_cast<double>(clock() - start)/CLOCKS_PER_SEC;
cout << "Time is: " << vremya << " seconds" << endl;
system("pause");
return 0;
}
欢迎来到Stack Overflow。请包括问题中的数据示例;不是链接,不是截图。 – Beta
考虑将3个值保存在一个结构中。当你读取每个值时,将第3列添加到一个集合或一个unordered_set,如果它尚未存在,并且它抛弃了这些数据。 –
@贝塔感谢您的意见 – dfdd