首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >西安交通大学915-2018-编程1

西安交通大学915-2018-编程1

作者头像
lexingsen
发布于 2022-02-24 19:51:14
发布于 2022-02-24 19:51:14
3110
举报
文章被收录于专栏:乐行僧的博客乐行僧的博客

题目描述:

解题思路:

  • 遍历序列,使用map存储

代码实现:

代码语言:javascript
复制
#include <iostream>
#include <map>
#include <string>
using namespace std;

void RemoveSpace(string &s) {
    string ans = "";
    for (auto & c : s) {
        if (c != ' ') {
            ans += c;
        }
    }
    s = ans;
}

int main() {
    string s;
    cout << "please input a str:" << endl;
    getline(cin, s);
    RemoveSpace(s);

    std::map<int, int> mp;
    for (auto c: s) {
        if (isdigit(c)) {
            cout << "c = " << c << endl;
            mp[c - '0']++;
        }
    }

    for (auto x : mp) {
        cout << x.first << " :" << x.second << endl;
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 题目描述:
  • 解题思路:
  • 代码实现:
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档