poj 2418 Hardwood Species (map)
题目:http://poj.org/problem?id=2418
在poj 上交题总是有各种错误,再次感叹各个编译器。
c++ AC代码,G++为超时,上代码:
#include<cstdio>
#include<string>
#include<map>
using namespace std; char s[];
int main()
{
map<string,int>mp;
map<string,int>::iterator iter;//声明迭代器
int sum=;
while(gets(s)!=NULL)
{
mp[s]++;
sum++;
}
iter=mp.begin(); //相当于指针
while(iter!=mp.end())
{
printf("%s %.4f\n",iter->first.c_str(),100.0*iter->second/sum); //.c_str() 是把字符串转换成能c能输出的
iter++;
}
return ;
}
这个代码是我第一次写的,不知道为什么 刚开始用了很多头文件,G++ wrong, c++ 编译错误
现在是 改了头文件后的 AC代码
#include<cstdio>
#include<string>
#include<iostream>
#include<map>
using namespace std; char s[];
int main()
{
map<string,int>mp;
map<string,int>::iterator iter;
int i,sum=;
while(gets(s)!=NULL)
{
mp[s]++;
sum++;
}
iter=mp.begin();
while(iter!=mp.end())
{
cout<<iter->first;
printf(" %.4lf\n",*1.0*iter->second/sum);
iter++;
}
return ;
}
吸取教训,以后 交c++,少用头文件
poj 2418 Hardwood Species (map)的更多相关文章
- [字典树] poj 2418 Hardwood Species
题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS Memory ...
- POJ 2418 Hardwood Species(STL在map应用)
职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 17986 Accepted: 713 ...
- POJ 2418 Hardwood Species
Hardwood Species Time Limit: 10000MS Memory Limit ...
- POJ - 2418 Hardwood Species(map,trie,BST)
1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...
- POJ 2418 Hardwood Species (哈希,%f 和 %lf)
我的错因: 本来改用%f输出,我用了%lf,结果编译器直接判定为错误(一部分编译器认为lf是没有错的).当时我还以为是hash出错了.. 方法不止一种: 方法 时间 空间 Hash 891ms 5 ...
- POJ 2418 Hardwood Species 【Trie树】
<题目链接> 题目大意: 给你一堆字符串,让你按字典序输出他们出现的频率. 解题分析: 首先,这是Trie数词频统计的题目,以Trie树的边储存字母,节点存储以该节点结尾的链所代表的字符串 ...
- 二叉搜索树 POJ 2418 Hardwood Species
题目传送门 题意:输入一大堆字符串,问字典序输出每个字符串占的百分比 分析:二叉搜索树插入,然后中序遍历就是字典序,这里root 被new出来后要指向NULL,RE好几次.这题暴力sort也是可以过的 ...
- POJ 2418 Hardwood Species( AVL-Tree )
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> ...
随机推荐
- C++ STL中迭代器失效的问题
my_container.erase(iter); 其中my_container是STL的某种容器,iter是指向这个容器中某个元素的迭代器.如果不是在for,while循环中,这种方式删除元素没有问 ...
- Java 类和对象
主要参考文献:王映龙<Java程序设计> 一:类的语法 [修饰符]class<类名>[extends父类名][implements接口列表]{ //类体} 1:修饰符 可选值为 ...
- 实现c++的string的split功能
今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...
- Fedora 17下安装Oracle 10g详细图文教程
一.硬件要求——内存 & swap & 硬盘 最小内存与swap: 1 GB of RAM & swap 建议内存与swap: 2 GB of RAM & swap [ ...
- Java中的异常处理(三) - 自定义异常处理
1.异常处理类 package second; public class MyException extends Exception { MyException (){ } MyException ( ...
- Memcache 分布式解决方案 之 : 普通 Hash 分布
<?php /* mhash * 其实说白了,就是为了实现返回0或1 */ function mmhash($key){ $md5 = substr(md5($key),0,8);//取该字符串 ...
- java实现附件预览(openoffice+swfTools+FlexPaper) (转载)
下边例子是在网上找了一个网友做的例子,在次记录 1.概述 主要原理 1.通过第三方工具openoffice,将word.excel.ppt.txt等文件转换为pdf文件 2.通过swfTools将pd ...
- sybase下convert函数第三个参数(时间格式)
convert(varchar(10),字段名,转换格式) 比如:1.select user_id,convert(varchar(10),dayts,11) as dates from tb_use ...
- 关于谷歌Chrome浏览器的两个Bug?
1.网络资源下载莫名其妙的网络错误(也不支持续传?有时打开文件是损坏的?) 2.超级链接莫名的成了html下载?
- 用上新的电脑装上了VS2013了
今天老魏终于把配置好的电脑拿回来了,16G的内存,I7 4770CPU.这回啊,老魏终于可以舍弃我的本本了,装上了SQL Server,虚拟机等等运行高内存的程序,感觉就是爽.明天老魏就可以用VS20 ...