百練的編碼框
由于顯示問題有的注釋
復(fù)制過去會(huì)自動(dòng)換行
原來是不要緊的啊
···
include<iostream>
include<stdio.h>
include<string.h>
using namespace std;
char map[] = "22233344455566677778889999";
char str[80], telNumbers[100000][9];
int compare(const void elem1, const voidelem2) {//為函數(shù)模板sort定義數(shù)組元素的比較函數(shù)
return(strcmp((char)elem1, (char)elem2));
}
void standardizeTel(int n) {
int j, k;//j用來計(jì)原來的字符數(shù)臊诊,k為標(biāo)準(zhǔn)化后的。
j = k = -1;
while (k < 8) {
j++;
if (str[j] == '-')//用“-”就會(huì)報(bào)錯(cuò): E0042 操作數(shù)類型不兼容("char" 和 "const char *")
continue;//跳出本次循環(huán)
k++;
if (k == 3) {
telNumbers[n][k] = '-';//第四位
k++;
}
if (str[j] >= 'A'&&str[j] <= 'Z') {
telNumbers[n][k] = map[str[j] - 'A'];
continue;//跳出本次循環(huán)
}
telNumbers[n][k] = str[j];
}
telNumbers[n][k] = '\0';
return;
}
int main()
{
int n, i, j;
bool noDuplicate;
cin >> n;
for (i = 0; i < n; i++) {
cin >> str;
standardizeTel(i);
}
qsort(telNumbers, n, 9, compare);
noDuplicate = true;
i = 0;
while (i < n) {
j = i;
i++;
while (i < n&&strcmp(telNumbers[i], telNumbers[j]) == 0)
i++;
if ((i - j) > 1) {
cout << telNumbers[j] << " " << i - j<<endl ;
noDuplicate = false;
}
}
if (noDuplicate)
{
cout << "No duplicates." << endl;
}
system("pause");
}
···