日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary

發布時間:2024/4/17 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。