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 |
HELP--wrong answer!#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { unsigned n, s_cpy = 1, mark = 0; vector<string> vec_str; cin >> n; for ( unsigned i = 0; i < n; i++ ) { string s, s_tmp; cin >> s; for ( unsigned j = 0; j < s.length(); j++ ) { switch( s.at(j) ) { case 'A': case 'B': case 'C': s.replace( j, 1, "2" ); break; case 'D': case 'E': case 'F': s.replace( j, 1, "3" ); break; case 'G': case 'H': case 'I': s.replace( j, 1, "4" ); break; case 'J': case 'K': case 'L': s.replace( j, 1, "5" ); break; case 'M': case 'N': case 'O': s.replace( j, 1, "6" ); break; case 'P': case 'R': case 'S': s.replace( j, 1, "7" ); break; case 'T': case 'U': case 'V': s.replace( j, 1, "8" ); break; case 'W': case 'X': case 'Y': s.replace( j, 1, "9" ); break; } } for ( unsigned k = 0; k < s.length(); k++ ) { if ( s.at(k) <= '9' && s.at(k) >= '0' ) { s_tmp += s.at(k); } } s_tmp.insert( 3, 1, '-' ); vec_str.push_back( s_tmp ); } sort( vec_str.begin(), vec_str.end() ); vector<string>::iterator it = vec_str.begin(); cout << endl; for ( ; it != vec_str.end(); ++it ) { while ( (it + 1) != vec_str.end() && *it == *(it + 1) ) { ++s_cpy; ++it; } if ( s_cpy != 1 ) { mark = 1; cout << *it << " " << s_cpy << endl; s_cpy = 1; continue; } } cout << endl; if ( mark == 0 ) { cout << "No duplicates"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator