[c语言]EmailAddresses(for hw)

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值