C++ code summary

  1. map<int, PersonClassifier>::iterator itmap<int, PersonClassifier> it的区别与联系

-----------------------------------------------------------------------------------

  1. C++
    并行程序的执行:

int
coreNum = omp_get_num_procs();

#pragma
omp parallel for
num_threads(coreNum) default(none)
\

private(po_num,
it, queryLabel) \

shared(al_random_select_num,
satisfy_size, satisfy_classifier_label, not_selected, random_index)

-----------------------------------------------------------------------------------

  1. 对输入的句子,统计每一个单词出现的次数:

int
main() {

map<string,
size_t>
word_count;

string
word;

while
(cin >>
word) {

++word_count[word];

}

for
(constauto
&w : word_count)

cout
<<
w.first <<"occurs"<<
w.second

<<
((w.second > 1) ? "times"
: "time")
<<
endl;

system("pause");

}

-----------------------------------------------------------------------------------

  1. 统计输入中每一个单词出现的次数(排除常见单词,如:”the”,
    ”a”, ”an”等等)

#include<iostream>

#include<string>

#include<map>

#include<set>

usingnamespace
std;

int
main() {

map<string,
size_t>
word_count;

set<string>
exclude = {"the",
"a",
"an"};

string
word;

while
(cin >>
word)

if
(exclude.find(word) ==
exclude.end())

++word_count[word];

for
(constauto
&w : word_count)

cout
<<
w.first <<"
occurs "<<
w.second <<"
times "<<
endl;

system("pause");

}

-----------------------------------------------------------------------------------

  1. 忽略大小写和标点,如:”example,”
    “example.” “Example”应该递增相同计数器。

   分为3步骤:

   1.先将所有的大写字母改为小写;

   2.将所有的标点符号都删去;

   3.将转换好的字符串返回.

 #include<iostream>
#include<fstream>
#include<map>
#include<string>
#include<algorithm> using namespace std; string &trans(string &s)
{
for (int p=; p<s.size(); p++){
if (s[p] >= 'A' && s[p] <= 'Z')
s[p] -= ('A'-'a');
else if (s[p] == ',' || s[p] == '.')
s.erase(p,);
} return s;
} int main(int argc, char *argv[])
{
ifstream in(argv[]);
if (!in){
cout<<"failed to open file !"<<endl;
exit();
} map<string, size_t> word_count;
string word;
while(in>>word)
++word_count(trans(word)); for (const auto &w:word_count)
cout<< w.first << " occurs " << w.second << " times " <<endl; return ;
}

   

-----------------------------------------------------------------------------------

  1. 对关联容器进行值初始化:

map<string, size_t> word_count;

set<string> exclude = {“the”, ”but”, “and”};

map<string, string> authers = { {“wang”, “xiao”},
{“wang”, ”kui”}, {“wang”, ”jianjun”} };

#include<iostream>

#include<string>

#include<map>

#include<set>

#include<vector>

usingnamespace
std;

int
main() {

vector<int>
ivec;

for
(vector<int>::size_type
i = 0; i != 20; ++i) {

ivec.push_back(i);

ivec.push_back(i);

}

set<int>
iset(ivec.cbegin(), ivec.end());

multiset<int>
miset(ivec.cbegin(), ivec.cend());

cout
<<
ivec.size() <<
endl;

cout
<<
iset.size() <<
endl;

cout
<<
miset.size() <<
endl;

system("pause");

}

  1. pair类型:

一个pair保存两个数据成员,pair是一个用来生成特定类型的模板。

pair<string, string> anon;

pair<string, size_t> word_count;

pair<string, vector<int>> line;

pair<string, string> auther {“wangxiao”, “wangkui”};

pair类型的数据成员是public的,两个成员分别为
first 和
second。

       9. ----

#include<iostream>
#include<string>
#include<map>
 
using namespace std;
 
int main() {
    map<string, size_t> word_count;
    string word;
    while (cin >> word) {
        ++word_count[word];
    }
        
    for (const auto &w : word_count)
        cout << w.first << "occurs" << w.second  
             << ((w.second > 1) ? "times" : "time") << endl;
 
    system("pause");
}

C++ code Summary --- 2015.11.8的更多相关文章

  1. 苹果被拒的血泪史。。。(update 2015.11)

    项目提交了N此了,也审核N次了,苹果的审核机制依旧那么不急不慢.昨天刚刚又被拒了.回忆下之前的,总结一下吧. 2015.04.28 昨天被拒非常亏,app的评级是17+,但是在app展示图里有一个比较 ...

  2. CODE FESTIVAL 2015 決勝(部分)

    CODE FESTIVAL 2015 決勝(部分) B - ダイスゲーム 题意: 给\(N\)个\(6\)个面骰子,然后问掷到概率最大的点数是多少. 分析: 随便打表随便发现是\(\huge\left ...

  3. 【转】Setting up SDL Extension Libraries on Code::Blocks 12.11

    FROM: http://lazyfoo.net/tutorials/SDL/06_extension_libraries_and_loading_other_image_formats/window ...

  4. 【转】Setting up SDL 2 on Code::Blocks 12.11

    FROM: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php Setting up SDL 2 on ...

  5. Twelfth scrum meeting 2015/11/9

    第一阶段的开发即将结束,工程代码已经集合完毕,计划在2015年11月10日发布第一阶段的成果,本次会议主要商量下一阶段需要完成的工作以及页面修改,还有测试人员的bug整理. 会议记录: 第一项:界面修 ...

  6. Murano Weekly Meeting 2015.11.11

    Meeting time: 2015.November.11th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting su ...

  7. Murano Weekly Meeting 2015.11.04

    Meeting time: 2015.November.4th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting sum ...

  8. 2015/11/9用Python写游戏,pygame入门(8):按钮和游戏结束

    昨天没有更新内容,今天相对多写一些. 因为我们已经基本完成游戏框架,但是游戏结束后,并不知道怎样比较好开始.我本来本着懒的原则,想结束后显示一个黑屏,然后你重新点一下鼠标就重新开始.但是那样实在太不像 ...

  9. Cheatsheet: 2015 11.01 ~ 11.30

    Golang Roadomatic: Node vs. Go Quick Guide to Golang for Java Developers 3 Go Gotchas Web Choosing a ...

随机推荐

  1. sidePagination: "server"和responseHandler: responseHandler

    bootstrapTable()中有两个属性 一个是sidePagination,表示服务器分页,responseHandler:responseHandler 表示回应操作的rows和total 两 ...

  2. vi中的批量替换

    举个例子啊: 将文件tihuan(假设此文本中字符a)中的所有字符a换成字符w,其命令为: 1.vi tihuan 2.按esc键 3.按shift+: 4.在:后输入    %s/a/w/g 就ok ...

  3. 作业5-需求分析(EX:南通大学成绩录入系统)

    产品利益相关者: 用户:南通大学各任课老师. 顾客:南通大学(教务处) 工程师:系统的开发,测试,维护,推广人员等 竞争性需求分析: N(需求) A(做法) B(好处) C(竞争) D(推广) 基础性 ...

  4. Android获取图片资源的4种方式

    1. 图片放在sdcard中 Bitmap imageBitmap = BitmapFactory.decodeFile(path) (path 是图片的路径,跟目录是/sdcard) 2. 图片在项 ...

  5. java作业5

    (一)用你的大数类实现加和减两个功能(乘除阶乘未实现) import java.util.Scanner; import java.io.IOException; import java.io.Inp ...

  6. CODEVS1533 互斥的数(哈希表)

    给定一个集合,要求一个最大子集,满足两两之间不互斥.对两个数x,y互斥的定义是,y=p*x. 先对集合中的数从小到大排序后线性扫,若一个数x可以取则取,取完之后p*x这个数不可取.由于数字较大,使用哈 ...

  7. Unity3D ShaderLab压缩混合纹理贴图

    Unity3D ShaderLab压缩混合纹理贴图 纹理可以用于存储大量的数据,我们可以把多个图像打包存储在单一的RGBA纹理上,然后通过着色器代码提取这些元素, 我们就可以使用每个图片的RGBA通道 ...

  8. 【转】Facebook React 和 Web Components(Polymer)对比优势和劣势

    原文转自:http://segmentfault.com/blog/nightire/1190000000753400 译者前言 这是一篇来自 StackOverflow 的问答,提问的人认为 Rea ...

  9. nginx的压力测试

    #-----------http_load讲解------------------------------------#   Web服务器压力测试工具常见的有http_load.webbench.ab ...

  10. Redis 设计与实现读书笔记一 Redis字符串

    1 Redis 是C语言实现的 2 C字符串是 /0 结束的字符数组 3 Redis具体的动态字符串实现 /* * 保存字符串对象的结构 */ struct sdshdr { // buf 中已占用空 ...