| ||||||||||
| 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 | |||||||||
你这个又是string,又是cin的,当然要超时了In Reply To:TLE Problem, Help-- Thanks, Posted by:KysShadow at 2006-08-19 16:32:14 > #pragma warning (disable : 4786)
>
> #include <algorithm>
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> string a[100002];
> int n;
>
> string Translate(string str) {
> int i;
> string New = "";
>
> for(i = 0; i < str.length(); i++) {
> switch(str[i]) {
> case 'A': case 'B': case 'C':
> New += "2";
> break;
> case 'D': case 'E': case 'F':
> New += "3";
> break;
> case 'G': case 'H': case 'I':
> New += "4";
> break;
> case 'J': case 'K': case 'L':
> New += "5";
> break;
> case 'M': case 'N': case 'O':
> New += "6";
> break;
> case 'P': case 'R': case 'S':
> New += "7";
> break;
> case 'T': case 'U': case 'V':
> New += "8";
> break;
> case 'W': case 'X': case 'Y':
> New += "9";
> break;
> case '-':
> break;
> default:
> New += str[i];
>
> break;
> };
> }
>
> return New;
> };
>
> void input() {
> int i;
>
> cin >> n;
> for(i = 1; i <= n; i++) {
> cin >> a[i];
>
> a[i] = Translate(a[i]);
> }
> }
>
> bool operator<(const string &t1, const string &t2) {
> return t1 < t2;
> }
>
> void output() {
> int i, j;
>
> i = 1;
> while(1) {
> if(i > n)
> break;
>
> j = i + 1;
> for(;; j++) {
> if(a[j] != a[i])
> break;
> }
>
> if(j - i >= 2)
> cout << a[i][0] << a[i][1] << a[i][2] << '-' << a[i][3] << a[i][4] << a[i][5] << a[i][6] << ' ' << j - i << '\n';
>
> i = j;
> }
> }
>
> int main() {
> input();
> sort(a + 1, a + n + 1);
> output();
>
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator