YTU 2774: Prepare for CET6

2774: Prepare for CET6

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 36   Solved: 34
[ Submit][ Status][ Web Board]

Description

Hard to force the CET4&6 is imminent, which makes most of the students a headache. This does not, Liu is trying his best to prepare for the CET6, trying to do a variety of previous year’s problem. But the most helpless for Liu is a quick read of this topic, so he thought of a thing does not make sense is that the statistical article the total number in different words. Here your task is to help Liu solve this problem.

Input

Multiple sets of data, each row is an article. Each article is consisted by lowercase letters and spaces, no punctuation, encounter # when the input end.

Output

Each group output only an integer, which alone make the trip, the integer representing the total number of different words in an article.

Sample Input

you are my friend
can you can a can as a canner can can a can
#

Sample Output

4
5
求一个句子中的不同单词的个数。用string数组保存单词个数然后排序然后比较得出个数。//有一个条件没写纠结了好久orz
AC代码:
#include <stdarg.h>
#include <iostream>
#include <math.h>
#include <iomanip>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    string s;char t;
    while(getline(cin,s)&&s!="#"){
        string p[1000];
        int len=s.length(),i=0,count=0,z;
       while(i<len){
           while(s[i]!=' '&&i<len){//忘记加i<len导致最后一个单词变的无限长orz。
                t=s[i++];
                p[count]+=t;
           }
              ++count;
               i++;
       }
        sort(p,p+count);
        int oo=count,k=0;
        for(i=1;i<count;++i){
            k=0;
            while(p[i]==p[i-1]){
             k++;i++;
            }
        oo-=k;
        }
        cout<<oo<<'\12';
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值