小白书训练-Andy's First Dictionary

来源:互联网 发布:c指针例题编程 编辑:程序博客网 时间:2024/05/20 05:10

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756

题意:给你一段文字,把所有的单词挑出来,然后排序打印、

首先是挑出来,用指针加数组轻轻松解决问题,然后排序,因为用数组不能快拍,便用了string,先转换为string然后一个快拍。

打印的时候不能打印重复的,因此,在打印的时候一个判断就好。

因为数组大小问题RE到死啊啊啊啊!O(≧口≦)O

代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <ctype.h>using namespace std;char str[50005][300];string s[50005];int main(){    int n = 0;    char tmp;    char *p = str[n];    while(~(tmp = getchar()))    {        if(isalpha(tmp))            *(p++) = towlower(tmp);        else        {            if(p > str[n])            {                *p = '\0';                n++;                p = str[n];            }        }    }    for(int i = 0;i < n;i++)        s[i] = str[i];    sort(s,s + n);    if(n > 0)        cout << s[0] << endl;    for(int i = 1;i < n;i++)    {        if(s[i] != s[i - 1])            cout << s[i] << endl;    }    return 0;}

梦续代码:http://www.hypo.xyz

0 0
原创粉丝点击