| ||||||||||
| 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 | |||||||||
wrong answer,不会改了,望指点#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
int map[] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0};
typedef struct
{
int num, count;
} NUM;
typedef vector<NUM> NUMBERS;
bool operator<(const NUM &lhs, const NUM &rhs)
{
return lhs.num < rhs.num;
}
bool operator==(const NUM &lhs, const NUM &rhs)
{
return lhs.num == rhs.num;
}
int transform(char *line)
{
int num = 0;
int i;
int len = strlen(line);
for(i = 0; i < len; ++i)
{
if(line[i] >= '0' && line[i] <= '9')
{
num = num * 10 + line[i] - '0';
}
if(line[i] >= 'A' && line[i] <= 'Z')
{
num = num * 10 + map[line[i] - 'A'];
}
}
return num;
}
void output(NUM& a)
{
char str[8];
sprintf(str, "%7d", a.num);
int i;
for(i = 0; i < 8; i++)
{
if(i == 3)
{
cout << '-';
}
if(str[i] == ' ')
{
cout << '0';
}
else
{
cout << str[i];
}
}
cout << ' ' << a.count << endl;
}
int main(int argc, char *argv[])
{
NUMBERS phonebook;
long n;
char line[80];
cin >> n;
//cin.getline(line, sizeof(line), '\n');
while(cin.get()!='\n')
{
;
}
while(n > 0)
{
--n;
cin.getline(line, sizeof(line), '\n');
int num = transform(line);
NUM temp = {num, 1};
NUMBERS::iterator ite = find(phonebook.begin(), phonebook.end(), temp);
if(ite == phonebook.end())
{
phonebook.push_back(temp);
}
else
{
++ite->count;
}
}
sort(phonebook.begin(), phonebook.end());
NUMBERS::iterator ite;
for(ite = phonebook.begin(); ite < phonebook.end(); ++ite)
{
if(ite->count > 1)
{
output(*ite);
}
}
for(ite = phonebook.begin(); ite->count <= 1 && ite < phonebook.end(); ++ite)
{
;
}
if(ite == phonebook.end())
{
cout << "No duplicates." << endl;
}
return EXIT_SUCCESS;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator