[PAT解题报告] 个位数统计 (15)

转载from http://tech-wonderland.net/blog/pat-basic-level-practise-1021-1025-solutions.html

解题思路: 水题, 利用hash表统计每个数字的个数即可. 下面是AC代码:
#include <map>
#include <iostream>
#include <string>

int main()
{
    std::string strInput;
    std::cin >> strInput;
    std::map<char, int> mapCounts;
    int iLen = strInput.size();
    for(int i = 0; i < iLen; ++i) {
        if(mapCounts.find(strInput[i]) == mapCounts.end())
            mapCounts[strInput[i]] = 1;
        else
            ++mapCounts[strInput[i]] ;;
    }
    for(auto it = mapCounts.begin(); it != mapCounts.end(); ++it) {
        std::cout << it->first << ':' << it->second << std::endl;
    }
    return 0;
}

全部评论
#include<iostream> #include<string.h> using namespace std; typedef struct{     int elem;     bool flag; }Node,Gewei[1001]; int main(){     char N[1001];     int n,count[10];     for(int i=0;i<=9;i++)count[i]=0;     Gewei G;     cin>>N;n=strlen(N);     for(int i=0;i<n;i++){         G[i].elem=N[i]-'0';         G[i].flag=0;}     for(int i=0;i<=9;i++){         for(int j=0;j<=n;j++){         if(G[j].flag==0&&G[j].elem==i){             count[i]++;G[j].flag=1;}         }     }     for(int i=0;i<=9;i++)     {if(count[i]!=0)cout<<i<<":"<<count[i]<<endl;}     system("pause");     return 0; } 在vs上运行输入0,输出0:1,但提交上去却显示输出0:2,哪位大佬能指导指导。
点赞 回复 分享
发布于 2019-04-26 15:57
奇怪了,我在devc++上运行没问题,但是提交说我错了 #include<stdio.h> int main(){ long k; int s[10]={0}; int i,count=0; scanf("%d",&k); do{ i=k%10; s[i]++; k/=10; }while(k>0); for(i=0;i<10;i++){ if(s[i]>0){ count++; if(count==1) printf("%d:%d",i,s[i]); else printf("\n%d:%d",i,s[i]); } } return 0; }
点赞 回复 分享
发布于 2017-02-16 21:37
import java.util.Scanner; import java.util.Set; import java.util.TreeMap; public class CalcGeWei { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); // String s= new String(); String line = sc.nextLine(); TreeMap<Character,Integer> tm = new TreeMap<Character,Integer>(); char[] ch = line.toCharArray(); for(char c:ch) { Integer i = tm.get(c); if(i==null) { tm.put(c, 1); } else { i++; tm.put(c, i); } } StringBuffer sb = new StringBuffer(); Set<Character> s1 = tm.keySet(); for(Character c2:s1) { sb.append(c2).append(":").append(tm.get(c2)).append("\n3"); } //System.out.println(tm); String result = sb.toString(); System.out.println(result); } }
点赞 回复 分享
发布于 2015-08-15 11:13

相关推荐

来个厂收我吧:首先,市场侧求职我不是很懂。 但是,如果hr把这份简历给我,我会觉得求职人不适合做产品经理。 问题点: 1,简历的字体格式不统一,排版不尽如人意 2,重点不突出,建议参考star法则写个人经历 3,印尼官方货币名称为印度尼西亚卢比(IDR),且GMV690000印尼盾换算为305人民币,总成交额不高。 4,右上角的意向职位在发给其他公司时记得删除。 5,你所有的经历都是新媒体运营,但是你要投市场营销岗位,jd和简历不匹配,建议用AI+提示词,参照多个jd改一下经历内容。 修改建议: 1,统一字体(中文:思源黑体或微软雅黑,英文数字:time new romans),在word中通过表格进行排版(b站学) 2,校招个人经历权重:实习经历=创业经历(大创另算)>项目经历>实训经历>校园经历 3,请将项目经历时间顺序改为倒序,最新的放最上方。 4,求职方向不同,简历文字描述侧重点也需要不同。
点赞 评论 收藏
分享
人间雪:简历最好只要一页,除非你牛逼到一页都写不下了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务