Hardwood Species(stl map)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/B
属于暴力
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <string>//string在这个头文件里;
#include <map>//map在这个头文件里;
#include <iostream>//cout在这个头文件里;
int cmp(const void *a,const void *b)
{
return strcmp((char *)a,(char *)b);
}
using namespace std;
char a[][];
int main()
{
int i=;
map<string,int>q;
//q.clear();
while(gets(a[i])!=NULL)
{
i++;
}
qsort(a,i,sizeof(a[]),cmp);
for(int j=;j<i;j++)
{
q[a[j]]++;
}
float rr;
rr=q[a[]]*100.0/i;
printf("%s %.4f\n",a[],rr);
for(int j=;j<i;j++)
{
if(strcmp(a[j],a[j-])!=)
{
rr=q[a[j]]*100.0/i;
printf("%s %.4f\n",a[j],rr);
}
}
return ;
}
现在STL刚入门
#include <string.h>
//#include <stdlib.h>//加了它编译错误
#include <stdio.h>
#include <string>
#include <map>
using namespace std; int main()
{
int tt=;
char a[];
double sum;
map<string,int>q;
map<string,int>::iterator it;
while(gets(a)!=NULL)
{
q[a]++;
tt++;
}
for(it=q.begin();it!=q.end();it++)
{
sum=100.0*((double)it->second/((double)tt));
printf("%s %.4lf\n",it->first.data(),sum);
}
return ;
}
这是学长以前写的
这个代码是我第一次写的,不知道为什么 刚开始用了很多头文件,G++ wrong, c++ 编译错误
现在是 改了头文件后的 AC代码

1 #include<cstdio>
2 #include<string>
3 #include<iostream>
4 #include<map>
5 using namespace std;
6
7 char s[100];
8 int main()
9 {
10 map<string,int>mp;
11 map<string,int>::iterator iter;
12 int i,sum=0;
13 while(gets(s)!=NULL)
14 {
15 mp[s]++;
16 sum++;
17 }
18 iter=mp.begin();
19 while(iter!=mp.end())
20 {
21 cout<<iter->first;
22 printf(" %.4lf\n",100*1.0*iter->second/sum);
23 iter++;
24 }
25 return 0;
26 }
27

Hardwood Species(stl map)的更多相关文章
- POJ 2418 Hardwood Species(STL在map应用)
职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...
- POJ - 2418 Hardwood Species(map,trie,BST)
1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...
- Hardwood Species(map)
http://poj.org/problem?id=2418 题意:给定一系列字符串,要求按字典序升序输出每个串,并输出每个串出现的百分比. 用map做的,交c++A了,G++ WA..so sad. ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- POJ2418——Hardwood Species(map映射)
Hardwood Species DescriptionHardwoods are the botanical group of trees that have broad leaves, produ ...
- POJ2418 Hardwood Species—二叉查找树应用
1. Hardwood Species原题描述 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 14326 Acce ...
- 洛谷 UVA10226 Hardwood Species
洛谷 UVA10226 Hardwood Species 洛谷评测传送门 题目描述 PDF 输入格式 输出格式 输入输出样例 输入 #1复制 输出 #1复制 题目翻译: 给定若干字符串,输出格式为:( ...
- POJ 2418 Hardwood Species
Hardwood Species Time Limit: 10000MS Memory Limit ...
- Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...
随机推荐
- 【线程】Thread中的join介绍
因为sleep.wait.join等阻塞,可以使用interrupted exception异常唤醒. 一.作用 Thread类中的join方法的主要作用就是同步,它可以使得线程之间的并行执行变为串行 ...
- getconf
用途 将系统配置变量值写入标准输出. 语法 getconf [ -v specification ] [ SystemwideConfiguration | PathConfiguration Pat ...
- php 函数合并 array_merge 与 + 的区别
array_merge()是PHP语言中的一个函数,作用是将两个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面.返回作为结果的数组. 如果输入的数组中有相同的字符串键名,该键的键值为最 ...
- Cocoa Touch框架
iOS – Cocoa Touch简介: iOS 应用程序的基础 Cocoa Touch 框架重用了许多 Mac 系统的成熟模式,但是它更加专注于触摸的接口和优化.UIKit 为开发者提供了在 iOS ...
- 在稳定性测试中,将测试结果持续填加进入html报告
公司需要设计一个稳定性测试,就是一直持续的跑不同的用例,直到人为停止,用例基本完成,基本框架思路就是随机选择一个testcase,跑完后输出结果.但存在一个问题,现在的unittest或nose测试报 ...
- 在UI自动化测试中使用flaky插件运行失败用例
在UI自动化测试中,有时候经常会提示跑用例失败,在单步或单个用例调试时,用例却成功,这个失败的因素主要有环境.代码或前端定位等原因. 可以看这篇文章<我们是如何让UI测试变得稳定的>中有详 ...
- java的前缀自增自减和后缀自增自减
2.前缀自增自减法(++a,--a): 先进行自增或者自减运算,再进行表达式运算. 3.后缀自增自减法(a++,a--): 先进行表达式运算,再进行自增或者自减运算 实例: 实例 public cla ...
- windows10 自带笔记本键盘禁止和开启
管理员打开cmd,输入sc config i8042prt start= disabled 然后重启就好了,注意 =后面有个空格. 恢复:sc config i8042prt start= deman ...
- Docker 利用registry创建私有仓库
一.Docker-registry镜像 下载地址 官方镜像下载比较慢,因为人品问题一直下载不成功,所以选择了国内的镜像. daocloud: https://hub.daocloud.io/ 还有 ...
- Centos6.5 (或Linux) 安装Elasticsearch
一.可以在网上下载对饮的版本:https://github.com/elastic/elasticsearch,本次安装的是5.5.3. 首先保证虚拟机上安装了jdk,jdk的版本只是是1.7或以上 ...