[c语言]EmailAddresses(for hw)

来源:互联网 发布:铁路工程预算软件 编辑:程序博客网 时间:2024/05/04 03:31

You’ve gathered some e-mail addresses from a variety of sources, and you want to send out a mass mailing to all of the addresses. However, you don’t want to send out duplicate messages. You need to write a program that reads all e-mail addresses and discards any that already have been input.

Input
The first line is a positive integer for the number of e-mail addresses which is smaller than 50. Then each of the e-mail addresses is input in one line.

Output
Output the new mailing list in lexicographic order. Each e-mail address in one line.

Note: ignore letter case when comparing two e-mail addresses, but the output is case sensitive.

Sample Input
10
toocle01@netsun.com
chuangling@chuangling.net
zjykrc@163.com
hahdjx@163.com
5663@sohu.com
toocle01@netsun.com
chenql_008@163.com
tsmoql@alibaba.com.cn
LYC@hzlasiji.com
zjykrc@163.com
Sample Output
5663@sohu.com
chenql_008@163.com
chuangling@chuangling.net
hahdjx@163.com
LYC@hzlasiji.com
toocle01@netsun.com
tsmoql@alibaba.com.cn
zjykrc@163.com

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>//在快排的比较函数中,把字符串存放在另一个指针中,把这个指针中的字符转化为小写再排序。不能改变原来指针的内容!//尽量使用strncpy, 同时最后一个参数要用strlen()+ 1,表示加上字符串最后一个/0;int comp(const void*a, const void*b) {    char p1[200];    char p2[200];    strncpy(p1, (char*)a, strlen((char*)a) + 1);    strncpy(p2, (char*)b, strlen((char*)b) + 1);    long length_1 = strlen(p1);    long length_2 = strlen(p2);    for (int i = 0; i < length_1; i++) {        p1[i] = tolower(p1[i]);    }    for (int i = 0; i < length_2; i++) {        p2[i] = tolower(p2[i]);    }    return strcmp((char*)p1,(char*)p2);}int main() {    int n;    scanf("%d", &n);    char address[100][100];    int i = 0;    while (n--) {        scanf("%s", address[i]);        i++;    }    qsort(address, i, sizeof(address[0]), comp);    int m;    for (m = 0; m < i - 1; m++) {        if (strcmp(address[m], address[m + 1]) == 0) {            strncpy(address[m], "0", strlen(address[m]) + 1);        }    }    for (m = 0; m < i; m++) {        if (strcmp(address[m], "0") != 0) {            printf("%s\n", address[m]);        }    }    return 0;}
0 0
原创粉丝点击