| | |
Can't figure out where my ACM sollution gives wrong answer.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 9
Reputation:
Solved Threads: 0
Hello to everybody.
I'm trying to solve an ACM task #755 called 487-3279. It's about telephone numbers, quite straightforward. But still something is wrong in my code, because the automatic control says "Wrong answer" and I can't find on which input it fails.
I tested it on Windows using MinGw. I fed big files (100 000 numbers) to it and it worked.
Please help me, I'm desperate now.
The code is:
I'm trying to solve an ACM task #755 called 487-3279. It's about telephone numbers, quite straightforward. But still something is wrong in my code, because the automatic control says "Wrong answer" and I can't find on which input it fails.
I tested it on Windows using MinGw. I fed big files (100 000 numbers) to it and it worked.
Please help me, I'm desperate now.
The code is:
C++ Syntax (Toggle Plain Text)
#include <cstdio> #include <iostream> #include <string> #include <map> #include <algorithm> using namespace std; int main() { int set_count; string s; getline(cin, s); sscanf(s.c_str(), "%d", &set_count); for (int j = 0; j < set_count; j++) { getline(cin, s); map<int,int> telnums; int count; getline(cin, s); sscanf(s.c_str(), "%d", &count); for (int i = 0; i < count; i++) { int cur_num = 0; getline(cin, s); for (unsigned int k = 0; k < s.length(); k++) { if (s[k] == '-') continue; int digit; switch (s[k]) { case '0': digit = 0; break; case '1': digit = 1; break; case '2': case 'A': case 'B': case 'C': digit = 2; break; case '3': case 'D': case 'E': case 'F': digit = 3; break; case '4': case 'G': case 'H': case 'I': digit = 4; break; case '5': case 'J': case 'K': case 'L': digit = 5; break; case '6': case 'M': case 'N': case 'O': digit = 6; break; case '7': case 'P': case 'R': case 'S': digit = 7; break; case '8': case 'T': case 'U': case 'V': digit = 8; break; case '9': case 'W': case 'X': case 'Y': digit = 9; break; default: digit = -1; break; }; if (digit != -1) cur_num = cur_num * 10 + digit; } map<int, int>::iterator TelefIter; TelefIter = telnums.find(cur_num); if(telnums.end() == TelefIter) { telnums[cur_num] = 1; } else { TelefIter->second++; } } bool hadsome = false; map<int, int>::const_iterator iter; for (iter = telnums.begin(); iter != telnums.end(); ++iter) { if (iter->second > 1) { hadsome = true; char str[8]; sprintf(str, "%07d", iter->first); printf("%c%c%c-%c%c%c%c %d\n", str[0], str[1], str[2], str[3], str[4], str[5], str[6], iter->second); } } if (!hadsome) printf("No duplicates.\n"); printf("\n"); } return 0; }
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++/CLI HtmlTextWriterStyle to formatted string
- Next Thread: How to deactivate setprecision?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






