Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

嗯。我也是这么写的。不知道是哪部分用的时间比较多?

Posted by mada_jlu at 2007-01-06 21:40:46 on Problem 1002
In Reply To:用C++STL写好容易超时啊 Posted by:undiaoyao at 2006-12-20 20:02:47
是iterator还是map?

#include <iostream>
#include <string>
#include <map>
using namespace std;

string to_tel_num(const string& str){
  string tel_num;
  for(int i=0;i<str.size();i++){
    if(tel_num.size() == 3)
      tel_num.append("-");
    switch(str[i]){
    case '-':
      break;
    case '0': 
      tel_num.append("0");
      break;
    case '1': 
      tel_num.append("1");
      break;
    case 'A': case 'B': case 'C': case '2':
      tel_num.append("2");
      break;
    case 'D': case 'E': case 'F': case '3':
      tel_num.append("3");
      break;
    case 'G': case 'H': case 'I': case '4':
      tel_num.append("4");
      break;
    case 'J': case 'K': case 'L': case '5':
      tel_num.append("5");
      break;
    case 'M': case 'N': case 'O': case '6':
      tel_num.append("6");
      break;
    case 'P': case 'R': case 'S': case '7':
      tel_num.append("7");
      break;
    case 'T': case 'U': case 'V': case '8':
      tel_num.append("8");
      break;
    case 'W': case 'X': case 'Y': case '9':
      tel_num.append("9");
      break;
    default:
      cerr<<"Error string!"<<endl;
    }
  }
  return tel_num;
}

int main(int argc, char** argv){
  int n;
  string tel_num_str;
  map<string,int> tel_num_map;
  bool has_out = false;

  if(!(cin>>n))
    return 1;
  for(int i=0;i<n;i++){
    if(!(cin>>tel_num_str))
      return 1;
    tel_num_map[to_tel_num(tel_num_str)]++;
  }

  for(map<string,int>::iterator iter = tel_num_map.begin();
      iter != tel_num_map.end();
      iter++)
    {
      if(iter->second !=1 ){
	has_out = true;
	cout<<iter->first<<" "<<iter->second<<endl;
      }
    }

  if(!has_out)
    cout<<"No duplicates."<<endl;
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator