UVA 10815 (字符串处理)

题目意思:


给你一些文字  包含空格 回车 各种标点

然后你从中找到不同的单词  然后输出就好


思路

 string 排序  然后把不同的扔出来 


坑点 

排序后的第一个点可能是空行 或者乱七八糟的字符什么的  在输出第一个点的时候千万要判断下  

我在这里wa无数次 辛酸~~


#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctype.h>
#include <cstdio>
using namespace std;
string S;
struct Node
{
	string s;
}str[5000005];
bool cmp(const Node &a, const Node &b) {
	return a.s < b.s;
}
int main()
{
    int cnt = 0;
	while (cin >> S) {
        for (int i = 0; i < S.length(); i ++) {
            if(isalpha(S[i])) {
                str[cnt].s += tolower(S[i]);
            } else cnt ++;
        }
        cnt ++;
	}
	if(!cnt)return 0;
	sort(str , str + cnt , cmp);
	if(isalpha(str[0].s[0]))
	cout << str[0].s << endl;
	for (int i = 1; i < cnt; i ++) {
        if(str[i].s != str[i - 1].s )
        cout << str[i].s << endl;
	}
}
/*
Adventures in
Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left."
Soooooo they went home.

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值