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 |
哪位大牛给帮忙看看,用stl怎么老是超时?用纯c也是超时啊,郁闷#include <stdio.h> #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { char c[24] = {'2', '2', '2', '3', '3', '3', '4', '4', '4', '5', '5', '5', '6', '6', '6', '7', '7', '7', '8', '8', '8', '9', '9', '9'}; vector<string> str; str.reserve(1000); double num; cin >> num; string str1, str2; for(int i = 0; i < num; i ++) { cin >> str1; for(int j = 0; j < str1.length(); j ++) { if((str1[j] >= 65)&&(str1[j] <= 80)) str2.insert(str2.end(), c[str1[j] - 65]); else if((str1[j] >= 82)&&(str1[j] <= 89)) str2.insert(str2.end(), c[str1[j] - 66]); else if((str1[j] >= 48)&&(str1[j] <= 57)) str2.insert(str2.end(), str1[j]); } str.push_back(str2); str1.erase(0, str1.length()); str2.erase(0, str2.length()); } sort(str.begin(), str.end()); bool Y = false; for(vector<string>::iterator k = str.begin(); k < str.end(); ) { int count = 0; vector<string>::iterator l = k + 1; while((l < str.end())&&(*k == *l)) { Y = true; count ++; k ++; l ++; } if(count != 0) { string s1 = *k; for(int m = 0; m < 7; m ++) { if(m == 2) { printf("%c", s1[m]); printf("-"); } else printf("%c", s1[m]); } printf(" %d\n", count + 1); } k = l; } if(Y == false) printf("No duplicates.\n"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator