吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1322|回复: 13
收起左侧

[已解决] C/C++练习第三贴

[复制链接]
25951741 发表于 2021-5-13 11:39
#include <iostream>
using namespace std;
#include <stack>
void test01()
{
        stack<int>s;
        for (int i = 0; i < 10; i++)
        {
                s.push(i);
        }
        while (!s.empty())
        {
                cout << "栈顶元素:"<<s.top()<<endl;
                s.pop();
        }
        cout <<"栈的大小为"<< s.size() << endl;
}


int main()
{
        test01();
        return 0;
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

BaconOle 发表于 2021-5-13 12:36
楼主加油
慕涯 发表于 2021-5-13 12:50
Gaho2002 发表于 2021-5-13 13:29
头像被屏蔽
tlf 发表于 2021-5-13 14:20
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 25951741 发表于 2021-6-6 15:53
#include <iostream>
#include <set>
using namespace std;
#if 0
void test01()
{
        set<int>s;
        s.insert(20);
        s.insert(40);
        s.insert(30);
        s.insert(50);
        s.insert(10);
        s.insert(60);
        pair<set<int>::iterator, bool>ret =s.insert(80);
        if (ret.second)
        {
                cout << "第一次插入成功" << endl;
        }
        else
        {
                cout <<"第一次插入失败" <<endl;
        }
        ret = s.insert(80);
        if (ret.second)
        {
                cout << "第er次插入成功" << endl;
        }
        else
        {
                cout << "第er次插入失败" << endl;
        }
        multiset<int>ms;
        ms.insert(20);
        ms.insert(20);
        ms.insert(20);
        ms.insert(20);
        for (multiset<int>::iterator it=ms.begin();it!=ms.end();it++)
        {
                cout << *it << " ";
        }
        cout << endl;
}
#endif
//pair对组
void test02()
{
        pair<string, int>p("汤姆",20);
        cout << "姓名" << p.first << "年龄" << p.second << endl;
        pair<string, int>p2 = make_pair("jerry", 30);
        cout << "姓名" << p2.first << "年龄" << p2.second << endl;
}

int main()
{
        test02();
        return 0;
}
 楼主| 25951741 发表于 2021-6-10 11:58
#include <iostream>
#include <map>
using namespace std;
void printmap(map<int, int>& m)
{
        for (map<int,int>::iterator it=m.begin();it!=m.end();it++)
        {
                cout << "KEY=" << it->first << "Value="<<(*it).second<<endl;
        }
        cout << endl;
}
void test01()
{
        map<int, int>m;
        m[0] = 10;
        m.insert(make_pair(1, 20));
        m.insert(pair<int, int>(2, 30));
        m.insert(make_pair(3, 61));
        m.insert(make_pair(4, 22));
        m.insert(make_pair(5, 23));
        printmap(m);
}

int mian()
{
        test01();
        return 0;
}
 楼主| 25951741 发表于 2021-6-11 07:03
#include <iostream>
#include<map>
#include <vector>
using namespace std;
#define chehua 0
#define meishu 1
#define yanfa 2
class worker
{
public:
        string m_name;
        int m_salary;
};
void createworker(vector<worker>&v)
{
        string nameseed = "ABCDEFGHIJ";
        for (int i = 0; i < 10; i++)
        {
                worker wok;
                wok.m_name = "员工";
                wok.m_name += nameseed[i];
                wok.m_salary = rand() % 10000 + 10000;
                v.push_back(wok);
        }
}
void test01(vector<worker>&v)
{
        for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
        {
                cout << "员工姓名:" << it->m_name << "  员工工资:" << it->m_salary << endl;
        }
        cout << endl;
}
void setgroup(vector<worker>&v,multimap<int ,worker>&m)
{
        for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
        {
                int deptid = rand() % 3;
                m.insert(make_pair(deptid, *it));
        }
}
void showworkbygourp(multimap<int,worker>&m)
{
        cout<<"策划部门信息:"<<endl;
        multimap<int,worker>::iterator pos= m.find(chehua);
        int count = m.count(chehua);//统计具体人数
        int index = 0;
        for (;pos != m.end()&&index<count; pos++,index++)
        {
                cout<<"姓名:"<<pos->second.m_name<<"工资为:"<<pos->second.m_salary<<endl;
        }
        cout<<"------------------------"<<endl;
        cout << "美术部门信息:" << endl;
        pos = m.find(meishu);
        count = m.count(meishu);//统计具体人数
        index = 0;
        for (; pos != m.end() && index < count; pos++, index++)
        {
                cout << "姓名:" << pos->second.m_name << "工资为:" << pos->second.m_salary << endl;
        }
        cout << "------------------------" << endl;
        cout << "研发部门信息:" << endl;
        pos = m.find(yanfa);
        count = m.count(yanfa);//统计具体人数
        index = 0;
        for (; pos != m.end() && index < count; pos++, index++)
        {
                cout << "姓名:" << pos->second.m_name << "工资为:" << pos->second.m_salary << endl;
        }

}

int main()
{
        vector<worker>vworker;
        createworker(vworker);
        test01(vworker);
        multimap<int, worker>mworker;
        setgroup(vworker,mworker);
        showworkbygourp(mworker);
        return 0;
}
 楼主| 25951741 发表于 2021-6-14 09:02
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;
class compare
{
public:
        bool operator()(int v1, int v2)
        {
                return v1 > v2;
        }
};
void test01()
{
        plus<int>p;
        cout<<p(10,10)<<endl;
        negate<int>n;
        cout << n(10) << endl;
}
void test02()
{
        vector<int>v;
        v.push_back(20);
        v.push_back(10);
        v.push_back(40);
        v.push_back(30);
        v.push_back(60);
        v.push_back(50);
        for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
        {
                cout << *it << " ";
        }
        cout << endl;
        sort(v.begin(),v.end(),greater<int>());
        for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
        {
                cout << *it << " ";
        }
        cout << endl;

}
int main()
{
        test01();
        test02();
        return 0;
}
 楼主| 25951741 发表于 2021-6-14 22:06
#include <iostream>
#include <graphics.h>
using namespace std;
#define wide 800
#define height 600
int main()
{
        initgraph(wide, height);
        SetWindowTextA(GetHWnd(), "贪玩蓝月");
        setbkcolor(LIGHTBLUE);
        cleardevice();//清屏
        //fillcircle(300, 250, 50);
        setfillcolor(RGB(100, 100, 100));//设置填充颜色
        fillrectangle(200, 50, 500, 100);
        settextcolor(RGB(0,255,0));//设置文字颜色
        settextstyle(50,0,"微软雅黑");//文字大小 间隔 字体
        setbkmode(TRANSPARENT);//文字设置透明
        outtextxy(300, 250, "首充6元");

        char chongzhi[] = "充值界面";
        int kuang=300/2-textwidth(chongzhi)/2;//文字的宽度
        int gao = 50/2-textheight(chongzhi) / 2;//文字的高度
        outtextxy(kuang + 200, gao + 50, chongzhi);
        getchar();
        closegraph();
        return 0;
}
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-1 07:13

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表