| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:TimeLimited。逐字节输入,维护输出队列,然后对队列快排。讲真,这题测试数据是针对快排的吗??在下不才,感觉理论上已经是最优解了In Reply To:Re:TimeLimited。逐字节输入,维护输出队列,然后对队列快排。讲真,这题测试数据是针对快排的吗??在下不才,感觉理论上已经是最优解了 Posted by:degiminnal at 2018-08-01 03:16:55 我把你的代码稍微改动了一下,用C语言完成通过了。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXS 10000000
int n, leno, flag, book[MAXS] = { 0 }, t[500] = { 0 };
char line[20] = { 0 }, ch;
char numstr[20];
int index;
void Input()
{
int i, Tel, counter;
for (i = 0; i <= 9; i++) t[i + 48] = i;
t['A'] = t['B'] = t['C'] = 2;
t['D'] = t['E'] = t['F'] = 3;
t['G'] = t['H'] = t['I'] = 4;
t['J'] = t['K'] = t['L'] = 5;
t['M'] = t['N'] = t['O'] = 6;
t['P'] = t['R'] = t['S'] = 7;
t['T'] = t['U'] = t['V'] = 8;
t['W'] = t['X'] = t['Y'] = 9;
scanf("%d", &n);
flag = leno = 0;
for (i = 0; i < n; i++)
{
counter = 0;
index = 0;
scanf("%s", numstr);
for (counter = Tel = 0; counter < 7; counter++)
{
ch=numstr[index];
index++;
if (ch == '-' || ch == 'Q' || ch == 'Z') {
counter--;
continue;
}
Tel = Tel * 10 + t[ch];
}
if (Tel > MAXS) { // 异常值保护模块
printf("ALERT\n");
system("pause");
}
flag += (book[Tel] == 0);
// book[]: Tel 的 frequency,outlist[]堆栈,有值
book[Tel]++;
}
}
void FormOut(int a)
{
int i;
for (i = 1000000; i >= 10000; i /= 10)
printf("%d", (a % (i * 10)) / i);
printf("-");
for (; i > 1; i /= 10)
printf("%d", (a % (i * 10)) / i);
printf("%d %d\n", a % 10, book[a]);
}
void Output()
{
int i;
if (flag == n) {
printf("No duplicates.\n");
return;
}
for (i = 0; i < MAXS; i++)
if (book[i]>1)
FormOut(i);
//printf("%d-%d %d\n", outlist[i]/10000, outlist[i]%10000, book[outlist[i]]);
}
int main()
{
Input();
//qsort(outlist, leno, sizeof(outlist[0]), cmp);
//test();
Output();
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator