[c语言]EmailAddresses(for hw)
2016-01-02 00:42
501 查看
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
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; }
相关文章推荐
- C语言 数组长度...int length = sizeof(stu) / sizeof(stu[0]);
- 学习c++的五十条忠告
- C语言-指针
- C++模板元编程(三)
- C语言指针-----指针与字符串
- C++笔记——动态链接库测试实例
- C++笔记——动态链接库测试实例
- C++笔记——拷贝对象
- C++笔记——创建一个动态链接库工程
- C语言-字符串
- c++实现回调函数及使用方法
- C语言指针-----指针与结构体
- C语言算法
- C语言指针-----指针与函数
- 利用C++11实现一个自动注册的工厂
- /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found的解决办法
- C语言指针-----指针与数组
- C++动态分配内存释放内存
- C/C++程序的内存区域划分
- C/C++综合測试题(三)