#include <iostream>
#include <map>
#include<string>
#include<iterator>
using namespace std;
int main()
{
map<string, int> T;
map<int, int> D;
T["a"] = 1;
T["b"] = 1;
T["c"] = 1;
T["e"] = 2;
T["f"] = 3;
T["g"] = 3;
map<string, int>::iterator it = T.begin();
map<int, int>::iterator its = D.begin();
while (it != T.end())
{
if (it->second == (++it)->second)
{
D.insert(map<int, int>::value_type(it->second, its->second++));
}
}
while (its != D.end())
{
cout << "重复的value为:" << its->first << "重复的次数为:" << its->second << endl;
}
return 0;
}
我不知道为什么,但是我感觉道理比较顺畅,我要去请教一下老师!
15题,与栈有关!下面是简单的我们设置了n=4,k=2,然后
#include<iostream>
#include <stack>
#include<iterator>
using namespace std;
int main()
{
stack<int>st;
stack<int>fuzhu;
st.push(4);
st.push(14);
st.push(24);
st.push(34);
//n=4.k=2
int i = 1;
int k = 2;
while (i < k)
{
fuzhu.push(st.top());
st.pop();
i++;
}
cout << st.top();
st.pop();
while (!(fuzhu.empty()))
{
st.push(fuzhu.top());
}
return 0;
}
现在我们定义一个函数,栈的情况给出,然后n与k为变量
#include<iostream>
#include <stack>
#include<iterator>
using namespace std;
void f(stack<int>A, int k)
{
stack<int>fuzhu;
int i = 1;
while (i < k)
{
fuzhu.push(A.top());
A.pop();
i++;
}
cout << A.top();
A.pop();
while (!(fuzhu.empty()))
{
A.push(fuzhu.top());
}
}
int main()
{
stack<int>st;
st.push(4);
st.push(14);
st.push(24);
st.push(34);
int b = 0;
cout << "请输入b" << endl;
cin >> b;
f(st, b);
return 0;
}