zoukankan      html  css  js  c++  java
  • hdu 2072 单词数

    题目需要注意的地方:统计一篇文章里 不同 单词的总数。

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 #include <map>
     5 using namespace std;
     6 
     7 int main(void)
     8 {
     9     char c;        //接收缓冲区中的一个字符
    10     char buf[100]; //临时存放单词的缓冲数组
    11     int count;     //记录buf的长度
    12     map<string, int> word; //用来判重
    13     while ('#' != (c = getchar()))
    14     {
    15         word.clear(); //初始化
    16         count = 0;
    17         if (' ' != c) //处理第一个字符
    18             buf[count++] = c;
    19         while ('
    ' != (c = getchar())) //处理后续字符
    20         {
    21             if (' ' == c && count != 0) //遇到空格并且buf中有内容,说明buf中这个单词读完,处理buf
    22             {
    23                 buf[count] = '';
    24                 word[buf] = 1;
    25                 count = 0;
    26             }
    27             else if ( ' ' != c )        //接收字符
    28                 buf[count++] = c;
    29             //遇到空格,但是buf中没有内容,那么不用做任何处理
    30         }
    31         if (0 != count)//count不等于0,说明最后一个单词还遗留在buf中,需要取出来
    32         {
    33             buf[count] = '';
    34             word[buf] = 1;
    35         }
    36         printf("%d
    ", word.size());
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    java多线程--线程和线程池
    java多线程--锁学习
    vue项目中使用iconfont
    组件封装-无数据组件
    添加自定义字体
    时间格式化(自定义格式)
    深度克隆方法
    LazyMan面试题
    lodash.throttle实现节流
    第6章:关系数据库理论(考研重点)
  • 原文地址:https://www.cnblogs.com/yongqiang/p/5665252.html
Copyright © 2011-2022 走看看