本文主要是介绍755 - 487--3279,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:755 - 487--3279
题目大意:找相同的电话号码
解题思路:将字母转换成数字,进行排序,最后统计输出。注意用scanf(“%d‘")后要接受一下数字后的回车,再接受空白行,后面的也一样。还有字符类型的数据大小和数字不一样,要进行转换(加减’0‘)。如果和我一样用 字符 - ’A‘的要注意,没有Q,所以到R之后的字符减了A还要减一。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>const int N = 1000005;
const int M = 20;int t, n;
char number[N][M];void change () {for(int i = 0; i < n; i++) {for(int j = 0; j < strlen(number[i]); j++) {if(number[i][j] >= 'A' && number[i][j] <= 'Z') {int m = (int)number[i][j] - 'A';if(m >= 16)m--;number[i][j] = 2 + m / 3 + '0';}}}
}int cmp_string (const void * _a, const void * _b) {char * a = (char*) _a;char * b = (char*) _b;return strcmp(a, b);
}int main() {int i, j;char ch;scanf("%d%*c", &t);
// scanf("%c", &ch);while(t--) {scanf("%c", &ch);scanf("%d%*c", &n);// scanf("%c", &ch);for(i = 0; i < n; i++) {j = 0;while(1) {scanf("%c", &ch);if(j == 3)number[i][j++] = '-';if(ch != '-' && ch != '\n')number[i][j++] = ch;else if(ch == '\n') {number[i][j] = '\0';break;}}}change();qsort(number, n, sizeof(number[0]), cmp_string);strcpy(number[n], "");int count = 0 ;bool bo = 0;for(i = 0; i < n; i++) {if(strcmp(number[i], number[i + 1]) == 0)count++;else if(count){bo = 1;printf("%s %d\n",number[i], count + 1);count = 0;}}if(!bo)printf("No duplicates.\n");if(t)printf("\n");}return 0;
}
这篇关于755 - 487--3279的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!