moveonz 2021-06-15 10:03 采纳率: 58.3%
浏览 16

各位大牛救救我,孩砸快废了

请用文字或图片来描述以下代码

#include<bits/stdc++.h>//万能头文件 
#include<stdlib.h>
using namespace std;

const int N = 10;//N种商品 
typedef struct brand
{
    int total;
    char cname[100];
}BRAND;

map<int, BRAND> mapBrand;

int main()
{
    //文件重定向 当前是读入从文件,输出在屏幕 
    freopen("p4.in","r",stdin);
    //freopen("p4.out","w",stdout);
    int id_temp;
    BRAND b_temp;
    //在内存中构建一个有三个属性的结构(品牌id,品牌名称,品牌当前销量)
    for(int i = 0; i<N; i++)//模拟读取数据库中的数据
    {
        cin >> id_temp >> b_temp.total >> b_temp.cname;
        mapBrand.insert(pair<int, BRAND>(id_temp, b_temp));
    }
    //给id是12598的品牌销量操作加1 
    map<int, BRAND>::iterator iter;
    iter = mapBrand.find(12598);
    if(iter != mapBrand.end())
    { 
       cout<<"brand is "<<iter->second.cname;
       iter->second.total++;
       cout<<" total is "<<iter->second.total << endl;
    } 
    else
           cout<<"Do not Find"<<endl;
       //给id是12598的品牌销量操作加1
    iter = mapBrand.find(12598);    
       if(iter != mapBrand.end())
    { 
       cout<<"brand is "<<iter->second.cname;
       iter->second.total++;
       cout<<" total is "<<iter->second.total << endl;
    } 
    else
           cout<<"Do not Find"<<endl;
       //查看id 21771 品牌当前的销量
       iter = mapBrand.find(21771);
    if(iter != mapBrand.end())
    { 
       cout<<"brand is "<<iter->second.cname;
       cout<<" total is "<<iter->second.total << endl;
    } 
    else
           cout<<"Do not Find"<<endl;
       //清空当前map
       mapBrand.erase(mapBrand.begin(), mapBrand.end());
       //注意这里没有把内存真正还给操作系统 ,linux下需要 malloc_trim函数才能彻底归还给操作系统 
       return 0;
       

  • 写回答

1条回答 默认 最新

  • SoftwareTeacher 《编程之美》作者 2021-06-15 10:09
    关注

    请写出你的初步思路。

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c