首页 > 其他 > 详细

hdu 2072单词数

时间:2014-08-02 23:22:34      阅读:484      评论:0      收藏:0      [点我收藏+]

单词数

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28671    Accepted Submission(s): 6877

Problem Description
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
 

 

Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
 

 

Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
 

 

Sample Input
you are my friend #
 

 

Sample Output
4
 

 

 

 

bubuko.com,布布扣
#include <stdio.h>
#include <string>
#include <set>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{

    char str[10002];
    while (gets(str))
    {

        if (0 == strcmp(str,"#")) break;
        set<string> s;
        string s1= "";
        s.insert(s1);
        for (int i =0 ; str[i] ;)
        {

            s1 = "";
            while (str[i]!= &&str[i])
            {
                s1 += str[i];
                i++;
            }
           
            s.insert(s1);
            while (str[i] ==  )  i++;
        }
        printf("%d\n",s.size()-1);
        s.clear();


    }

    return 0;
}
View Code

 

 

#include <stdio.h>

#include <string>

#include <set>

#include <string.h>

#include <iostream>

using namespace std;

int main() {

    char str[10002];

    while (gets(str))

    {

        if (0 == strcmp(str,"#"))    break;

        set<string> s;

        string s1= "";

        s.insert(s1);

        for (int i =0 ; str[i] ;)

        {

            s1 = "";    

         while (str[i]!=‘ ‘&&str[i])  

                             {                 s1 += str[i];                 i++;             }  

                      s.insert(s1);  

           while (str[i] == ‘ ‘)  i++;                    }    

   

  printf("%d\n",s.size()-1);   

      s.clear();

    }

    return 0;

}

 

 

bubuko.com,布布扣
#include <stdio.h>
#include <string>
#include <set>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{

    char str[10002];
    char str1[10002];
    set<string> s;
    string s1;
    while (gets(str))
    {
        if (0 == strcmp(str,"#")) break;
        while (sscanf(str,"%s",str1)!=EOF)
        {
            s1=str1;
            s.insert(s1);
            int i=0;
            while (str[i]== &&str[i]) i++;
            while (str[i]!= &&str[i]) str[i++]= ;

        }

        printf("%d\n",s.size());
        s.clear();
    }

    return 0;
}
View Code

 

#include <stdio.h>

#include <string>

#include <set>

#include <string.h>

#include <iostream>

using namespace std;

int main() {

    char str[10002];

    char str1[10002];

    set<string> s;

    string s1;

    while (gets(str))

    {        

if (0 == strcmp(str,"#")) break;

        while (sscanf(str,"%s",str1)!=EOF)

        {             s1=str1;      

                  s.insert(s1);    

         int i=0;          

   while (str[i]==‘ ‘&&str[i])                    i++;    

         while (str[i]!=‘ ‘&&str[i])               str[i++]=‘ ‘;

        }

        printf("%d\n",s.size());  

       s.clear();  

   }

    return 0;

}

 

**************************************************************************************************************8

 

 

思考一下

bubuko.com,布布扣
#include <stdio.h>
#include <string>
#include <set>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{

    char str[10002];
    char str1[10002];
    set<string> s;
    string s1;
    while (gets(str))
    {
        if (0 == strcmp(str,"#")) break;
        while (sscanf(str,"%s",str1)!=EOF)
        {
            s1=str1;
            s.insert(s1);
    cout<<s1<<endl;
            printf("%s\n",str);
            system("pause");
            int i=0;
            while (str[i]== &&str[i]) i++;
            while (str[i]!= &&str[i]) str[i++]= ;

        }

        printf("%d\n",s.size());
        s.clear();
    }

    return 0;
}
View Code

bubuko.com,布布扣

 

hdu 2072单词数,布布扣,bubuko.com

hdu 2072单词数

原文:http://www.cnblogs.com/2014acm/p/3887596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!