UVA 10815(待修改)

本文针对UVA10815题目提供了一种解决方案,利用C++中的set容器来实现去除重复单词并按字典序输出的功能。通过对输入文本进行预处理,将所有单词转换为小写形式,并利用set的特性来确保输出单词的唯一性和有序性。

题意:读入一串字符串,输出按字典序,从小到大不重复输出所有单词,恰好满足set的特点,第一次用set,结果自己测试对,不过一直WA,求路过的大神指点..


 

/**********************
* author:crazy_石头
* Pro:UVA 10815
* algorithm: set
* Judge Status:wrong Answer
* Time:ms
* Memory:K
***********************/

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <ctype.h>
#include <algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<=(n);i++)
const int maxn=500+5;

set<string> myset;
set<string>::iterator st;

char text[maxn];
char tarjet[maxn];

inline void transform()
{
    int len=strlen(tarjet);
    rep(i,len)
    {
        if(isupper(tarjet[i]))
        tarjet[i]+=32;
    }
}//大写转化为小写;

int main()
{
    int len,i,cnt;
    myset.clear();
    while(gets(text))
    {
        cnt=0;
        len=strlen(text);
        text[len]='\0';
        text[len+1]='\0';//读入文章;

        rep(i,len)
        {
            if(isalpha(text[i]))
            {
                tarjet[cnt++]=text[i];
            }
            else
            {
                tarjet[cnt]='\0';
                cnt=0;//准备重新读取字符;
                transform();
                string ss;
                ss=tarjet;
                myset.insert(ss);
            }
        }
    }
    for(st=myset.begin();st!=myset.end();st++)
    {
        cout<<*st<<endl;
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Moria )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值