Can't figure out where my ACM sollution gives wrong answer.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 9
Reputation: Infeligo is an unknown quantity at this point 
Solved Threads: 0
Infeligo Infeligo is offline Offline
Newbie Poster

Can't figure out where my ACM sollution gives wrong answer.

 
0
  #1
Mar 2nd, 2008
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:

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. int set_count;
  12. string s;
  13. getline(cin, s);
  14. sscanf(s.c_str(), "%d", &set_count);
  15.  
  16. for (int j = 0; j < set_count; j++)
  17. {
  18. getline(cin, s);
  19. map<int,int> telnums;
  20.  
  21. int count;
  22. getline(cin, s);
  23. sscanf(s.c_str(), "%d", &count);
  24.  
  25. for (int i = 0; i < count; i++)
  26. {
  27. int cur_num = 0;
  28. getline(cin, s);
  29. for (unsigned int k = 0; k < s.length(); k++)
  30. {
  31. if (s[k] == '-') continue;
  32. int digit;
  33. switch (s[k])
  34. {
  35. case '0': digit = 0; break;
  36. case '1': digit = 1; break;
  37. case '2':
  38. case 'A':
  39. case 'B':
  40. case 'C': digit = 2; break;
  41. case '3':
  42. case 'D':
  43. case 'E':
  44. case 'F': digit = 3; break;
  45. case '4':
  46. case 'G':
  47. case 'H':
  48. case 'I': digit = 4; break;
  49. case '5':
  50. case 'J':
  51. case 'K':
  52. case 'L': digit = 5; break;
  53. case '6':
  54. case 'M':
  55. case 'N':
  56. case 'O': digit = 6; break;
  57. case '7':
  58. case 'P':
  59. case 'R':
  60. case 'S': digit = 7; break;
  61. case '8':
  62. case 'T':
  63. case 'U':
  64. case 'V': digit = 8; break;
  65. case '9':
  66. case 'W':
  67. case 'X':
  68. case 'Y': digit = 9; break;
  69. default: digit = -1; break;
  70. };
  71.  
  72. if (digit != -1)
  73. cur_num = cur_num * 10 + digit;
  74. }
  75.  
  76. map<int, int>::iterator TelefIter;
  77. TelefIter = telnums.find(cur_num);
  78.  
  79. if(telnums.end() == TelefIter)
  80. {
  81. telnums[cur_num] = 1;
  82. }
  83. else
  84. {
  85. TelefIter->second++;
  86. }
  87.  
  88. }
  89.  
  90. bool hadsome = false;
  91. map<int, int>::const_iterator iter;
  92. for (iter = telnums.begin(); iter != telnums.end(); ++iter)
  93. {
  94. if (iter->second > 1)
  95. {
  96. hadsome = true;
  97. char str[8];
  98. sprintf(str, "%07d", iter->first);
  99. printf("%c%c%c-%c%c%c%c %d\n",
  100. str[0], str[1], str[2], str[3],
  101. str[4], str[5], str[6], iter->second);
  102. }
  103. }
  104.  
  105. if (!hadsome) printf("No duplicates.\n");
  106.  
  107. printf("\n");
  108. }
  109.  
  110. return 0;
  111. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Can't figure out where my ACM sollution gives wrong answer.

 
0
  #2
Mar 2nd, 2008
It will help to know what inputs you used that caused the problem.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: Infeligo is an unknown quantity at this point 
Solved Threads: 0
Infeligo Infeligo is offline Offline
Newbie Poster

Re: Can't figure out where my ACM sollution gives wrong answer.

 
0
  #3
Mar 3rd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Can't figure out where my ACM sollution gives wrong answer.

 
0
  #4
Mar 3rd, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC