http://poj.org/problem?id=2418

【注意】

1. 输入有空格,用

char str[maxn];
while(gets(str)){
str[]!='\0';
}

string str;
while(getline(cin,str)&&!(str=='')){ }

2.

char str[maxn];
string s;
s=str;

而不是

char str[maxn];
string s;
int len=strlen(str);
for(int i=;i<len;i++) s[i]=str[i];

【Accepted】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map> using namespace std;
const int maxn=;
char str[maxn];
map<string, int> mp;
map<string, int>::iterator it;
int main(){
int cnt=;
while(gets(str)){
if(str[]=='\0') break;
string s;
/*
//错误写法
int len=strlen(str);
for(int i=0;i<len;i++){
s[i]=str[i];
}
*/ //正确写法
s=str;
if(mp.find(s)!=mp.end()){
mp[s]+=;
}else{
mp[s]=;
}
cnt++;
}
for(it=mp.begin();it!=mp.end();it++){
cout<<it->first<<" ";
printf("%.4f\n",*it->second*1.0/cnt);
} return ;
}

【gets getline的用法 char[]转化为str】poj 2418的更多相关文章

  1. c++中字符输入函数cin.getline在输入char与string时的不同

    cin.getline在输入char时: using namespace std; ; char name[ArSize]; char dessert[ArSize]; cout << & ...

  2. C++:cin、cin.getline()、getline()的用法

    主要内容: 1.cin用法 2.cin.getline()用法 3.getline()用法 3.注意的问题 一.cin>> 用法1:输入一个数字或字符 #include <iostr ...

  3. C++ cin.get及getline的用法

    1.cin.get() 从指定的输入流中提取一个字符,函数的返回值就是这个字符.文件结束符会返回EOF,一般以-1代表EOF. #include<iostream> using names ...

  4. C++中getline的用法

    在看紫皮书的时候看到getline,然后查了查具体用法,记录下来. #include"iostream" #include"string" using name ...

  5. pandas格式化str为时间,pandas将int转化为str

    code_300['HISTORY_DATE'] = code_300['HISTORY_DATE'].map(str)code_300['HISTORY_DATE'] = pd.to_datetim ...

  6. c/c++读取一行可以包含空格的字符串(getline,fgets用法)

    1.char[]型 char buf[1000005]; cin.getline(buf,sizeof(buf)); 多行文件输入的情况: while(cin.getline(buf,sizeof(b ...

  7. awk中的system和getline的用法

    system只能对命令的输出结果输出到终端. getline在awk中可以使命令的输出结果传到一个变量中保存. # awk 'BEGIN{system("date")|getlin ...

  8. 【转载】C++ getline函数用法

    https://www.cnblogs.com/xiaofeiIDO/p/8574042.html 摘要: 通过getline()函数一个小小的实例,那么把getline()函数作为while的判断语 ...

  9. django自定义标签,int转化为str类型

    1.在app中创建templatetags目录,目录名必须为templatetags 2.在目录templatetags中创建一个.py文件,例如 strFilter.py strFilter.py ...

随机推荐

  1. shell流程语句使用介绍

    1)使用if.case.read例子1:#!/bin/bash#读取终端输入的字符read -p "Please input a Number:" nn1=`echo $n|sed ...

  2. VC操作WORD文档总结

    一.写在开头 最近研究word文档的解析技术,我本身是VC的忠实用户,看到C#里面操作WORD这么舒服,同时也看到单位有一些需求,就想尝试一下,结果没想到里面的技术点真不少,同时网络上的共享资料很多, ...

  3. vue.js与react.js相比较的优势

    vue.js的简介 vue.js是一个javascript mvvm库,它是以数据驱动和组件化的思想构建的.我们平时多用js去操作dom,vue.js则是使用了数据绑定驱动来操作dom的,也就是说创建 ...

  4. Java数据结构和算法(五)--希尔排序和快速排序

    在前面复习了三个简单排序Java数据结构和算法(三)--三大排序--冒泡.选择.插入排序,属于算法的基础,但是效率是偏低的,所以现在 学习高级排序 插入排序存在的问题: 插入排序在逻辑把数据分为两部分 ...

  5. CPP-网络/通信:WebService

    工具:vc2003 //引入相关头文件,连接动态库,定义全局变量. //***************************************************** #include & ...

  6. C# 读App.config配置文件[2]: .Net Core框架

    C# 读App.config配置文件[1]:.Net Framework框架 C# 读App.config配置文件[2]: .Net Core框架 网上都是.net framework读取配置文件的方 ...

  7. 使用custom elements和Shadow DOM自定义标签

    具体的api我就不写 官网上面多  如果不知道这个的话也可以搜索一下 目前感觉这个还是相当好用的直接上码. <!DOCTYPE html> <html lang="en&q ...

  8. HDU-1455-木棒

    这题的话,我们,定义一个结构体,然后把木棒从大到小排序. 这些木棒如果是由多根等长木棒组成的,那目标长度一定大于等于其中最长的木棒长度,所这就是我们搜索的下限. 上限就是所有的木棒组成了一根木棒,就是 ...

  9. 【动态规划】bzoj1044: [HAOI2008]木棍分割

    需要滚动优化或者short int卡空间 Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍 ...

  10. Git学习——撤销修改

    git checkout -- <file> 当你修改完一个工作区的文件后,使用git status查看当前的状态.其中有说明,接下来你可以git add <file> 去添加 ...