C++ code Summary --- 2015.11.8
C++ code summary
map<int, PersonClassifier>::iterator it与 map<int, PersonClassifier> it的区别与联系
-----------------------------------------------------------------------------------
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)
-----------------------------------------------------------------------------------
对输入的句子,统计每一个单词出现的次数:
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");
}
-----------------------------------------------------------------------------------
统计输入中每一个单词出现的次数(排除常见单词,如:”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");
}
-----------------------------------------------------------------------------------
忽略大小写和标点,如:”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 ;
}
-----------------------------------------------------------------------------------
对关联容器进行值初始化:
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");
}
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的更多相关文章
- 苹果被拒的血泪史。。。(update 2015.11)
项目提交了N此了,也审核N次了,苹果的审核机制依旧那么不急不慢.昨天刚刚又被拒了.回忆下之前的,总结一下吧. 2015.04.28 昨天被拒非常亏,app的评级是17+,但是在app展示图里有一个比较 ...
- CODE FESTIVAL 2015 決勝(部分)
CODE FESTIVAL 2015 決勝(部分) B - ダイスゲーム 题意: 给\(N\)个\(6\)个面骰子,然后问掷到概率最大的点数是多少. 分析: 随便打表随便发现是\(\huge\left ...
- 【转】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 ...
- 【转】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 ...
- Twelfth scrum meeting 2015/11/9
第一阶段的开发即将结束,工程代码已经集合完毕,计划在2015年11月10日发布第一阶段的成果,本次会议主要商量下一阶段需要完成的工作以及页面修改,还有测试人员的bug整理. 会议记录: 第一项:界面修 ...
- Murano Weekly Meeting 2015.11.11
Meeting time: 2015.November.11th 1:00~2:00 Chairperson: Serg Melikyan, PTL from Mirantis Meeting su ...
- Murano Weekly Meeting 2015.11.04
Meeting time: 2015.November.4th 1:00~2:00 Chairperson: Serg Melikyan, PTL from Mirantis Meeting sum ...
- 2015/11/9用Python写游戏,pygame入门(8):按钮和游戏结束
昨天没有更新内容,今天相对多写一些. 因为我们已经基本完成游戏框架,但是游戏结束后,并不知道怎样比较好开始.我本来本着懒的原则,想结束后显示一个黑屏,然后你重新点一下鼠标就重新开始.但是那样实在太不像 ...
- Cheatsheet: 2015 11.01 ~ 11.30
Golang Roadomatic: Node vs. Go Quick Guide to Golang for Java Developers 3 Go Gotchas Web Choosing a ...
随机推荐
- Setup Factory 打包.netframework 2.0
在setup factory 的安装目录下的Dependencies中新建目录dotnet20/并放入dotnetfx2.0.exe: Dependencies目录中再加xml文件dotnet20.x ...
- (二)iOS如何把所有界面的状态栏的字体颜色都设置为白色
第一步:在info.plist中添加一个字段:view controller -base status bar 设置为NO 第二步:在一个所有界面都继承的父类里添加: if (IOS7_OR_LATE ...
- Screen对象
document.write("Screen-width:"+screen.width+"Screen-height:"+screen.height);docu ...
- OpenSesame:一个能够攻击fixed-pin设备的工具
OpenSesame是一种设备,这种设备可以通过无线技术来打开任何一个设有固定密码的车库门,我从中发现了一个攻击无线固定pin码设备的新方法. 演示视频以及详细信息: opensesame源代码:ht ...
- 通过AssetsLibrary框架访问所有相片
该框架下有几个类,ALAssetsLibrary,ALAssetsGroup,ALAsset,ALAssetsFilter,ALAssetRepresentation. ALAssetsLibrary ...
- 初始React Native
1.何是React Native: React-Native是:Facebook 在2015年初React.js技术研讨大会上公布的一个开源项目.支持用开源的JavaScript库React.js来开 ...
- Windows系统定时重开或者关机
at 6:00 /every:M,T,W,Th,F,S,Su cmd /c shutdown -r -t 60 (每天早上6点自动重启一次) at 0:00 /every:M,T,W,Th,F,S,S ...
- Android重写getResources规避用户调整系统字体大小影响Android屏幕适配
Android屏幕适配一直是一个头疼的问题.除此之外还要考虑APP在实际应用场景中,用户千奇百怪的设置,最常见的用户设置行为就是设置手机的字体大小,比如把字体设置成超大或者超小,这对屏幕适配又带来额外 ...
- Android SoundPool.play方法的音量与系统音量的关系
Android中播放音频,除了使用MediaPlayer,还可以使用SoundPool.SoundPool使用音效池的概念来管理多个短促的音效,对于需要短促的提示音的场景特别合适. 通常调用Sound ...
- Xcode Snippets
在Double Encore,我们写的代码都是干净,可重用的——不过,有时候并不能完全做到.如在使用pragma mark的时候.下面就是一个示例: #pragma mark - UIViewCo ...