[STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary
生活随笔
收集整理的這篇文章主要介紹了
[STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、set
集合 哦....對了,set有自動按照字典序排序功能。。。。。
聲明和插入操作
#include <cstdio> #include <vector> #include <set> using namespace std; int main(){vector<int> v;for (int i = 0; i < 10; i++){v.push_back(i);v.push_back(i);}set<int> s;s.insert(v.begin(), v.end());//因為是集合,所以重復的元素不會被重復插入for (set<int>::iterator it = s.begin(); it != s.end(); it++)printf("%d\n", *it);printf("\n");return 0; }?
刪除操作
這個一般都用的是erase()--->刪除指定的元素或者刪除指定部分的元素 和 clear()--->清除所有元素 操作如下:
set<int> s;s.erase(2); s.clear();?
查找操作
set支持upper_bound() lower_bound() find()等操作 舉個例子:
set<int> s;set<int>::iterator it;it = s.find(5); //查找鍵值為5的元素if (it != s.end()) //找到了 cout << *it << endl;?
2、isalpha()
判斷字符ch是否為英文字母,若為英文字母,返回非0(小寫字母為2,大寫字母為1)。若不是字母,返回0。 具體用法見下
3、stringstream()
輸入輸出轉換操作 具體用法見下
4、tolower()
是一種函數,功能是把字母字符轉換成小寫,非字母字符不做出處理。 具體用法見下
下面是該題代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<sstream> #include<set> using namespace std; set<string>aa; string s,cur; int main(){std::ios::sync_with_stdio(false);while(cin>>s){for(int i=0;i<s.length();i++){if(isalpha(s[i])) s[i]=tolower(s[i]);else s[i]=' ';}stringstream ss(s);while(ss>>cur) aa.insert(cur);}for(set<string>::iterator it=aa.begin();it!=aa.end();it++){cout<<*it<<endl;}return 0; }
轉載于:https://www.cnblogs.com/TbIblog/p/11193641.html
總結
以上是生活随笔為你收集整理的[STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单表数据量过大处理策略
- 下一篇: linux源码Makefile的详细分析