#include <iostream>
#include <vector>
#include <cstddef>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <set>
#include <limits>
#include <functional>
#include <numeric> template <class DataType>
void ReadMatFromFile(std::string &filename, std::vector<std::vector<DataType> > &lines_feat) {
std::ifstream vm_info(filename.c_str());
std::string lines;
DataType var;
std::vector<DataType> row; lines_feat.clear(); while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break;
std::stringstream stringin(lines);
row.clear(); while(stringin >> var) {
row.push_back(var);
}
lines_feat.push_back(row);
}
} void ReadStringFromFile(std::string &filename, std::vector<std::string> &in_string) {
std::ifstream vm_info(filename.c_str());
std::string lines, var; while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break;
std::stringstream stringin(lines); while(stringin >> var) {
in_string.push_back(var);
}
}
} void ReadDataFromFile(std::string &filename, std::vector<std::string> &lines_feat) {
std::ifstream vm_info(filename.c_str());
std::string lines; lines_feat.clear(); while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break; lines_feat.push_back(lines);
}
} void ReadSetFromFile(std::string &filename, std::set<std::string> &lines_feat) {
std::ifstream vm_info(filename.c_str());
std::string lines; lines_feat.clear(); while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break; lines_feat.insert(lines);
}
} void ProcessSet(std::set<std::string> &s1, std::set<std::string> &s2) {
std::set<std::string>::const_iterator it=s1.begin(), find_it; for(; it!=s1.end(); ++it) {
find_it=s2.find(*it);
if(find_it == s2.end()) {
std::cout<<*it<<", not found.\n";
}
}
} std::string lowerCase(const std::string& s) {
std::string lower(s);
for(size_t i=;i<s.length();++i) {
lower[i]=tolower(lower[i]);
}
return lower;
} std::string letters(const std::string& s) {
std::string letter;
for(size_t i=;i<s.length();++i) {
char ch=s.at(i);
bool flag=false;
if((ch>= && ch<=)) {
ch=ch+;
flag=true;
}
else if((ch>= && ch<=) || (ch>= && ch<=)) {
flag=true;
}
else {
;
}
if(flag) {
letter.push_back(ch);
}
}
letter.push_back('\0');
return letter;
} template <class T1, class T2>
int MatMultiply(const std::vector<std::vector<T1> > &Mata, const std::vector<std::vector<T2> > &Matb, std::vector<std::vector<T1> > &MatOut) {
if(Mata.at().size() != Matb.size()) {
std::cout<<"not match!\n";
return -;
}
for(size_t i=; i<Mata.size(); ++i) {
for(size_t j=; j<Matb.at().size(); ++j) {
std::vector<T2> col;
col.clear();
for(size_t k=; k<Matb.size(); ++k) {
col.push_back(Matb.at(k).at(j));
}
MatOut.at(i).at(j)=inner_product(Mata.at(i).begin(), Mata.at(i).end(), col.begin(), );
}
}
return ;
} template <class T1, class T2, class T3>
void outer_product(const std::vector<T1> &inst1, const std::vector<T2> &inst2, std::vector<std::vector<T3> > &out) {
std::vector<T3> temp_row(inst2.size()); for(typename::std::vector<T1>::const_iterator it=inst1.begin();it!=inst1.end();++it) {
transform(inst2.begin(), inst2.end(), temp_row.begin(), bind2nd(std::multiplies<T1>(), *it));
out.push_back(temp_row);
}
} std::vector<std::string> split(const std::string& s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s); while(std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
} int stringtoint(const std::string& s) {
std::istringstream iss(s);
int num;
return iss>>num?num:;
} void printip(const std::string& s) {
std::vector<std::string> temp, ip_segment; temp=split(s, '-');
ip_segment=split(temp.front(), '.'); std::string ip_start=ip_segment.back(), ip_end=temp.back();
int start, end;
start=stringtoint(ip_start);
end=stringtoint(ip_end); for(size_t i=start;i<=end;++i) {
std::cout<<ip_segment[]<<"."<<ip_segment[]<<"."<<ip_segment[]<<"."<<i<<"\n";
}
} template <class T>
void Display2DVector(std::vector<std::vector<T> > &vv) {
for(size_t i=;i<vv.size();++i) {
for(typename::std::vector<T>::const_iterator it=vv.at(i).begin();it!=vv.at(i).end();++it) {
std::cout<<*it<<" ";
}
std::cout<<"\n";
}
std::cout<<"--------the total of the 2DVector is "<<vv.size()<<std::endl;
} int main() {
std::string file1("iplist1"), file2("iplist2");
std::set<std::string> s_ip1, s_ip2; ReadSetFromFile(file1, s_ip1);
ReadSetFromFile(file2, s_ip2); ProcessSet(s_ip1, s_ip2); return ;
}

数据读进set,进行后处理的更多相关文章

  1. (转)sscanf() - 从一个字符串中读进与指定格式相符的数据

    (转)sscanf() - 从一个字符串中读进与指定格式相符的数据 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, stri ...

  2. [置顶] sscanf() - 从一个字符串中读进与指定格式相符的数据

    在做一道九度上机题时,突然发现sscanf()函数非常有用,就顺便从网上搜集资料整理一下. sscanf() 的作用:从一个字符串中读进与指定格式相符的数据. 原型: int sscanf (cons ...

  3. RTKLIB编译及RTCM数据读取样例

    1.RTKLIB简介 RTKLIB是全球导航卫星系统GNSS(global navigation satellite system)的标准&精密定位开源程序包,RTKLIB由日本东京海洋大学( ...

  4. windows环境下nutch2.x 在eclipse中实现抓取数据存进mysql详细步骤

    nutch2.x 在eclipse中实现抓取数据存进mysql步骤 最近在研究nutch,花了几天时间,也遇到很多问题,最终结果还是成功了,在此记录,并给其他有兴趣的人提供参考,共同进步. 对nutc ...

  5. JavaScript怎么把对象里的数据整合进另外一个数组里

    https://blog.csdn.net/qq_26222859/article/details/70331833 var json1 = [ {"guoshui":[ 3000 ...

  6. spring boot: @Entity @Repository一个简单的数据读存储读取

    spring boot: @Entity @Repository一个简单的数据读存储读取 创建了一个实体类. 如何持久化呢?1.使用@Entity进行实体类的持久化操作,当JPA检测到我们的实体类当中 ...

  7. Java将数据写进excel

    Java将数据写进excel Java将数据写进excel class User { private String name ; private String password; public Use ...

  8. BIML 101 - ETL数据清洗 系列 - BIML 快速入门教程 - 将文本文件(csv)数据导进数据库

    第二节 将文本文件数据导进数据库 该小节介绍如何用BIML生成ssis包,将货币文本导入到数据库currency的表中. SSIS组件: Connection Manager组建管理connectio ...

  9. sscanf linux-c从一个字符串中读进与指定格式相符的数据

    https://www.cnblogs.com/lanjianhappy/p/6861728.html 函数原型: Int sscanf( string str, string fmt, mixed ...

随机推荐

  1. Far Relative’s Problem (贪心 计算来的最多客人)

    Description Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n  ...

  2. vector元素的删除 remove的使用 unique的使用

    在vector删除指定元素可用以下语句 : v.erase(remove(v.begin(), v.end(), element), installed.end()); 可将vector中所有值为el ...

  3. 笔记——python风格规范

    分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Python会将 圆括号, 中括号和花括号 ...

  4. ..net 3.5新特性之用this关键字为类添加扩展方法

    具体用法如下: public static class ClassHelper { //用this 声明将要吧这个方法附加到Student对象 public static bool CheckName ...

  5. Thinkphp5.0 的使用模型Model的获取器与修改器

    Thinkphp5.0 的使用模型Model的获取器.修改器.软删除 一.获取器 在model中使用 get+字段名+Attr,可以修改字段的返回值. 数据库中性别保存为,0未知.1男.2女,查询时返 ...

  6. Servlet的客户端请求

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/client-request.html: 当浏览器请求网页时,它会向Web服务器发送大量信息,这些 ...

  7. easyui datagrid-detailview 嵌套高度自适应

    实现效果 原因 异步加载,明细展开时,可能会遇到父列表不能自动适应子列表高度的变化 具体代码 $('#centerdatagrid').datagrid({ url:'${ctx}/offer/off ...

  8. node使用npm一句命令停止某个端口号 xl_close_port

    一命令停止某一个端口号,再也不怕端口号被占用了.. 1.插件背景 开启项目的时候,跑不起来了? 很多时候的原因就是,依赖版本,依赖的包未安装,再就是端口号被占用 例如: 这时候,我们做法就是: 1.到 ...

  9. Check ini style config tool

    INI style config is like below [section] # comment key = value Sometimes we want to check the config ...

  10. 如何查看sqlalchemy执行的原始sql语句?

    SQLAlchemy打开SQL语句方法如下,echo=true将开启该功能: engine = create_engine("<db_rul>", echo=True) ...