#include<iostream>#include<queue>#include<stack>#include<vector>usingnamespace std;intmain(){int N =0;
cin>>N;
priority_queue<int> pq;for(int i =0; i < N; i++){int num =0;
cin>>num;
pq.push(num);}
stack<int> st;
st.push(pq.top());
pq.pop();while(!pq.empty()){if(st.top()!= pq.top()){
st.push(pq.top());}
pq.pop();}
vector<int> res;while(!st.empty()){
res.push_back(st.top());
st.pop();}for(int i =0; i < res.size(); i++){
cout << res[i]<< endl;}return0;}
4.字符串分隔
#include<iostream>#include<vector>#include<string>usingnamespace std;voidprocess(vector<string>& res, string& s){while(s.size()%8!=0){
s +="0";}for(int i =0; i < s.size()-7; i +=8){
string tmp = s.substr(i,8);//cout<<tmp<<endl;
res.push_back(tmp);}}intmain(){
string str ="";
vector<string> res;while(cin>>str){process(res, str);}for(int i =0; i < res.size(); i++){
cout<<res[i]<<endl;}return0;}
5.进制转换
#include<unordered_map>#include<algorithm>#include<math.h>usingnamespace std;
unordered_map<char,int> m ={{'0',0},{'1',1},{'2',2},{'3',3},{'4',4},{'5',5},{'6',6},{'7',7},{'8',8},{'9',9},{'A',10},{'B',11},{'C',12},{'D',13},{'E',14},{'F',15}};voidprocess(string s,int& res){reverse(s.begin(), s.end());//cout<<s<<endl;for(int i =0; i < s.size(); i++){
res += m[s[i]]*pow(16, i);//cout<<res<<endl;}}intmain(){
string str ="";int res =0;while(cin>>str){process(str, res);}
cout<<to_string(res)<<endl;return0;}
6.质数因子
#include<iostream>#include<vector>usingnamespace std;intmain(){long num =0;//
cin >> num;
vector<int> res;for(int i =2; i * i <= num;++i){//2是最小的质因子 只需要验证一半便知2是不是质因子//cout<<num<<endl;while(num % i ==0){
res.push_back(i);
num /= i;}}//如果m=1,则while循环中刚好被质数分解完,如果大于1,说明没有被分解完,m就是那最后一个质数//同时,这句也可以应对输入为质数的特殊情况if(num >=2) res.push_back(num);for(int i =0; i < res.size(); i++){
cout << res[i]<<" ";}
cout << endl;return0;}
#include<iostream>#include<map>#include<vector>#include<algorithm>usingnamespace std;/*struct cmp{
bool operator()(pair<int, int>& m, pair<int, int>& n) {
return m.first < n.first;
}
};*/intmain(){int num =0;
cin >> num;
map<int,int> m;//map内部本身就是按照key的大小顺序进行存储的//vector<pair<int, int>> vec;for(int i =0; i < num; i++){int key =0, value =0;while(cin>>key>>value){if(!m[key]){
m[key]= value;}else m[key]+= value;//不存在时赋值,存在时累加//vec.push_back(make_pair(key, value));}}//sort(vec.begin(), vec.end(), cmp());//map内部本身就是按照key的大小顺序进行存储的for(map<int,int>::iterator/*auto*/ iter = m.begin(); iter != m.end(); iter++){
cout<<iter->first<<" "<<iter->second<<endl;}return0;}
9.提取不重复的整数
#include<iostream>#include<string>#include<algorithm>#include<unordered_set>usingnamespace std;intmain(){int num =0;
cin >> num;
string str =to_string(num);reverse(str.begin(), str.end());
unordered_set<char> tmp;int res =0;for(int i =0; i < str.size(); i++){if(tmp.count(str[i])==0){
res = res *10+(str[i]-'0');}
tmp.insert(str[i]);}
cout << res << endl;return0;}