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:

#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;


		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");


	return 0;
8 Years
Discussion Span
Last Post by Ancient Dragon

That's the thing about ACM. All inputs that I tested gave (IMHO) correct outputs. But the input the automatic controller used that gave wrong answer is unknown.


Post an example of the input data you tried. Maybe what the controlller did was feed your program bogus (invalid) data to see how your program would handle it.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.