UVA 10815 Andy's First Dictionary

来源:互联网 发布:小猪cms源码下载 编辑:程序博客网 时间:2024/04/30 11:55

输入一些句子,从中读出所有单词,都转为小写,去掉重复,按字典序,由小到大输出。

#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<cmath>///LOOP#define REP(i, n) for(int i = 0; i < n; i++)#define FF(i, a, b) for(int i = a; i < b; i++)#define FFF(i, a, b) for(int i = a; i <= b; i++)#define FD(i, a, b) for(int i = a - 1; i >= b; i--)#define FDD(i, a, b) for(int i = a; i >= b; i--)///INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RFI(n) scanf("%lf", &n)#define RFII(n, m) scanf("%lf%lf", &n, &m)#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)#define RS(s) scanf("%s", s)///OUTPUT#define PN printf("\n")#define PI(n) printf("%d\n", n)#define PIS(n) printf("%d ", n)#define PS(s) printf("%s\n", s)#define PSS(s) printf("%s ", n)///OTHER#define PB(x) push_back(x)#define CLR(a, b) memset(a, b, sizeof(a))#define CPY(a, b) memcpy(a, b, sizeof(b))#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}using namespace std;typedef long long LL;typedef pair<int, int> P;const int MOD = 100000000;const int INFI = 1e9 * 2;const LL LINFI = 1e17;const double eps = 1e-6;const double pi = acos(-1.0);const int N = 55555;const int M = 222;const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int num;struct str{    char ch[M];}s[N];bool cmp(str a, str b){    return strcmp(a.ch, b.ch) < 0;}bool check(){    int l;    char c = getchar();    l = 0;    while(!isalpha(c))    {        if(c == EOF)return 0;        c = getchar();    }    s[num].ch[l++] = tolower(c);    while(isalpha(c = getchar()))s[num].ch[l++] = tolower(c);    s[num++].ch[l++] = '\0';    return 1;}int main(){    //freopen("input.txt", "r", stdin);    //freopen("output.txt", "w", stdout);    while(check());    sort(s, s + num, cmp);    REP(i, num - 1)if(strcmp(s[i].ch, s[i + 1].ch))PS(s[i].ch);    if(strcmp(s[num - 2].ch, s[num - 1].ch))PS(s[num - 1].ch);    return 0;}


原创粉丝点击