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 |
TLE???#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; const string map("22233344455566677778889999"); string convert(const string &s); int main() { vector<string> teleBook; teleBook.reserve(100000); string teleNum, teleNum_c; bool noDuplicate = true; int n,c; c = 0; cin >> n; while (c++ < n) { cin >> teleNum; teleNum_c = convert(teleNum); teleBook.push_back(teleNum_c); } sort(teleBook.begin(),teleBook.end()); for (int i = 0, j; i < n; i++) { for (j = i + 1; j < n; j++) if (teleBook[j] != teleBook[i]) break; if (j - i > 1) { cout << teleBook[i] << ' ' << j - i << endl; noDuplicate = false; } i = j - 1; } if (noDuplicate) cout << "No duplicates." << endl; system("PAUSE"); return 0; } string convert(const string &s) { int i, k; i = k = 0; string s2; int len = s.length(); while (k < 8 && i < len) { if (s[i] == '-') { i++; continue; } if (k == 3) { s2.push_back('-'); k++; } if (s[i] >= 'A' && s[i] <= 'Z') { k++; s2.push_back(map[s[i] - 'A']); } else { k++; s2.push_back(s[i]); } i++; } return s2; } 难道用vector和string就会超时 我明明 reserve了100000了的呀 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator