一、今日内容
map
1·重载了[ ],像数组高级版
2·写法:例:map<string,int> month_name表示月份名到月份编号;赋值: month_name["July"] = 7
3·例程:Ananagrams
#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
map<string,int> cnt;
//将单词s进行标准化,小写
string repr(const string& s)
{
string ans = s;
for(int i = 0;i < ans.length(); i++)
ans[i] = tolower(ans[i]);
sort(ans.begin(),ans.end());
return ans;
}
int main()
{
int n = 0;
string s;
while(cin >> s)
{
if(s[0] == '#') break;
words.push_back(s);
string r = repr(s);
if(!cnt.count(r)) cnt(r) = 0;
cnt[r]++;
}
vector<string> ans;
for(int i = 0; i < words.size(); i++)
if(cnt[repr(words[i])] == 1) ans.push_back(words[i]);
sort(ans.begin(),ans.end());
for(int i = 0; i < ans.size();i++)
cout<<ans[i]<<'\n';
return 0;
}
此题与Andy's First Dictionary 的区别 在于 A用set,此题用map;A仅按字典顺序排序即可,不区分大小写;此题要求较多。
总之,没看懂。
二、明天计划:a·结合c++标准程序库再研究研究算法的一些基础知识,不能急,基础先打牢;
b·结合c++教材 回顾模板部分。这玩意得慢慢啃,静下来慢慢干。