c++:poj 1002,样例没问题,但是提交上去不论怎样都WA,求大佬看看哪里有问题 10
#include<iostream>#include<map>usingnamespacestd;intreal_num(constchar*ori){intresult...
#include <iostream>
#include <map>
using namespace std;
int real_num(const char* ori) {
int result=0;
char bit;
int CtoN[] = { 2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9 };
for (int i = 0; ; ++i) {
bit = ori[i];
if (bit == '\0')
break;
if (bit == '-')
continue;
else if (bit <= '9' && bit >= '0')
result = result*10+bit-'0';
else if (bit >= 'A' && bit < 'Z' && bit!='Q') {
result = result * 10 + CtoN[bit - 'A'];
}
}
return result;
}
void count_and_print(map<int,int>& nums) {
bool flag = true;
map<int, int>::iterator itr;
int current;
for (itr=nums.begin(); itr != nums.end(); ++itr) {
if (itr->second>1) {
current = itr->first;
if (current>=1000000)
cout << current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else {
if (current>=100000)
cout <<'0'<< current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else if(current >=10000)
cout <<"00"<< current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else if(current >=1000)
cout << "000" << '-' << current << ' ' << itr->second << endl;
else if (current >=100)
cout << "000-0" << current << ' ' << itr->second << endl;
else if (current >=10)
cout << "000-00" << current << ' ' << itr->second << endl;
else
cout << "000-000" << current << ' ' << itr->second << endl;
}
flag = false;
}
}
if (flag)
cout << "No duplicates." << endl;
}
int main() {
size_t num;
cin >> num;
map<int, int> my_map;
char tmp[1000];
for (int i = 0; i<num; ++i) {
cin >> tmp;
++my_map[real_num(tmp)];
}
count_and_print(my_map);
return 0;
} 展开
#include <map>
using namespace std;
int real_num(const char* ori) {
int result=0;
char bit;
int CtoN[] = { 2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9 };
for (int i = 0; ; ++i) {
bit = ori[i];
if (bit == '\0')
break;
if (bit == '-')
continue;
else if (bit <= '9' && bit >= '0')
result = result*10+bit-'0';
else if (bit >= 'A' && bit < 'Z' && bit!='Q') {
result = result * 10 + CtoN[bit - 'A'];
}
}
return result;
}
void count_and_print(map<int,int>& nums) {
bool flag = true;
map<int, int>::iterator itr;
int current;
for (itr=nums.begin(); itr != nums.end(); ++itr) {
if (itr->second>1) {
current = itr->first;
if (current>=1000000)
cout << current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else {
if (current>=100000)
cout <<'0'<< current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else if(current >=10000)
cout <<"00"<< current / 10000 << '-' << (current % 10000) << ' ' << itr->second << endl;
else if(current >=1000)
cout << "000" << '-' << current << ' ' << itr->second << endl;
else if (current >=100)
cout << "000-0" << current << ' ' << itr->second << endl;
else if (current >=10)
cout << "000-00" << current << ' ' << itr->second << endl;
else
cout << "000-000" << current << ' ' << itr->second << endl;
}
flag = false;
}
}
if (flag)
cout << "No duplicates." << endl;
}
int main() {
size_t num;
cin >> num;
map<int, int> my_map;
char tmp[1000];
for (int i = 0; i<num; ++i) {
cin >> tmp;
++my_map[real_num(tmp)];
}
count_and_print(my_map);
return 0;
} 展开
展开全部
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
using namespace std;
int num[] =
{
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
};
map<int, int> s;
char buf[128];
int main()
{
int t;
scanf("%d", &t);
bool flag = false;
for(int i = 0; i < t; i++)
{
scanf("%s", &buf);
int c = 0;
for(int j = 0; buf[j]; j++)
{
if(isdigit(buf[j]))
c = c * 10 + buf[j] - '0';
else if(isalpha(buf[j]))
c = c * 10 + num[ buf[j] - 'A' ];
}
s[c]++;
}
for(map<int, int>::iterator it = s.begin(); it != s.end(); it++)
if(it->second > 1)
{
flag = true;
printf("%03d-%04d %d\n", it->first / 10000, it->first % 10000, it->second);
}
if(!flag)
puts("No duplicates.");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询