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)的更多相关文章

  1. POJ 2418 Hardwood Species(STL在map应用)

    职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...

  2. POJ - 2418 Hardwood Species(map,trie,BST)

    1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...

  3. Hardwood Species(map)

    http://poj.org/problem?id=2418 题意:给定一系列字符串,要求按字典序升序输出每个串,并输出每个串出现的百分比. 用map做的,交c++A了,G++ WA..so sad. ...

  4. [ACM] POJ 2418 Hardwood Species (Trie树或map)

    Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 713 ...

  5. POJ2418——Hardwood Species(map映射)

    Hardwood Species DescriptionHardwoods are the botanical group of trees that have broad leaves, produ ...

  6. POJ2418 Hardwood Species—二叉查找树应用

    1. Hardwood Species原题描述   Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 14326   Acce ...

  7. 洛谷 UVA10226 Hardwood Species

    洛谷 UVA10226 Hardwood Species 洛谷评测传送门 题目描述 PDF 输入格式 输出格式 输入输出样例 输入 #1复制 输出 #1复制 题目翻译: 给定若干字符串,输出格式为:( ...

  8. POJ 2418 Hardwood Species

                                                     Hardwood Species Time Limit: 10000MS   Memory Limit ...

  9. Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...

随机推荐

  1. Use Reentrant Functions for Safer Signal Handling(译:使用可重入函数进行更安全的信号处理)

    Use Reentrant Functions for Safer Signal Handling 使用可重入函数进行更安全的信号处理 How and when to employ reentranc ...

  2. Win8应用开发 入门篇(三) UX交互导航模式

    导航模式(Windows 应用商店应用)   在本文中 分层模式 画布上导航 顶部应用栏 语义式缩放 相关主题 组织 Windows 应用商店应用中的内容,以便用户可以轻松而直观地进行导航.使用正确的 ...

  3. Material Design系列第四篇——Defining Shadows and Clipping Views

    Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Custom ...

  4. 【WEB前端系列之CSS】CSS3动画之Animation

    前言 动画使用示例https://github.com/AndyFlower/web-front/tree/master/css3/loading 学习CSS3中Animation之前先来看一个动画特 ...

  5. webapck html-loader实现资源复用

    1.安装 npm i html-loader --save-dev 2.项目目录 layout文件夹下的footer.html文件为: <script type="text/javas ...

  6. LeetCode 30 Substring with Concatenation of All Words(确定包含所有子串的起始下标)

    题目链接: https://leetcode.com/problems/substring-with-concatenation-of-all-words/?tab=Description   在字符 ...

  7. linux alternatives命令详解

    alternatives是Linux下的一个功能强大的命令.只能在root权限下执行.如系统中有几个命令功能十分类似,却又不能随意删除,那么可以用 alternatives 来指定一个全局的设置. a ...

  8. 使用Btrace来动态监控方法的参数和返回值

    btrace简介: btrace是一种动态跟踪分析一个运行中的Java应用程序的工具,它基于java的探针技术动态地向目标应用程序的字节码注入追踪代码(字节码追踪),这些追踪字节码追踪代码使用Java ...

  9. Cocoa Touch框架

    iOS – Cocoa Touch简介: iOS 应用程序的基础 Cocoa Touch 框架重用了许多 Mac 系统的成熟模式,但是它更加专注于触摸的接口和优化.UIKit 为开发者提供了在 iOS ...

  10. JDBC改进版

    将setObject隐藏,用反射获取model里面的数据 /** * @Date 2016年7月19日 * * @author Administrator */ package com.eshore. ...