zoukankan      html  css  js  c++  java
  • hdoj-1251-统计难题【map】

    统计难题

    Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
    Total Submission(s): 23029 Accepted Submission(s): 9640


    Problem Description
    Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).

    Input
    输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每一个提问都是一个字符串.

    注意:本题仅仅有一组測试数据,处理到文件结束.

    Output
    对于每一个提问,给出以该字符串为前缀的单词的数量.

    Sample Input
    banana band bee absolute acm ba b band abc

    Sample Output
    2 3 1 0

    Author
    Ignatius.L

    Recommend
    Ignatius.L | We have carefully selected several similar problems for you: 1075 1247 1671 1298 1800

    #include<iostream>
    #include<stdio.h>
    #include<string> 
    #include<string.h>
    #include<map>
    using namespace std;
    map<string,int> u;
    int main(){
    
    	char s1[20],s2[20],s3[20];
    	while(gets(s1)){
    		int len=strlen(s1);
    		if(len==0) break;
    		for(int i=0;i<len;++i){
    			s2[i]=s1[i];
    		    s2[i+1]='';
    			u[s2]++;
    		}		
    	}
    	while(gets(s3)){
    	//	printf("##%s
    ",s3);
    		printf("%d
    ",u[s3]);
    		//printf("null
    ");
    	}
    	return 0;
    }


  • 相关阅读:
    Google 地图小例子
    实现网站的中英文转换
    必须掌握的八个【cmd 命令行】
    C#发送email
    sql 参数化查询,添加,删除
    SqlDataReader使用序数索引器
    DataSet数据筛选和排序
    Connect Propertity
    SqlDataReader读取数据
    SqlDataReader读取数据
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/6746813.html
Copyright © 2011-2022 走看看