| ||||||||||
| 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 | |||||||||
为什么VC下正确但是提交在线编译是错的呢?// phoneMatch.cpp : Defines the entry point for the console application.
//
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define LN(X) ((int)(X.length()))
#define SZ(X) ((int)(X.size()))
#define MAX 50
class phoneMatch{
private:
int exchange[MAX][2];
int resultNum[MAX];
public:
inline int exchangeChar(char ch)
{
if(ch >= 'A' && ch <= 'C')
return 2;
if(ch >= 'D' && ch <= 'F')
return 3;
if(ch >= 'G' && ch <= 'I')
return 4;
if(ch >= 'J' && ch <= 'L')
return 5;
if(ch >= 'M' && ch <= 'O')
return 6;
if(ch == 'P' || ch == 'R' || ch == 'S')
return 7;
if(ch >= 'T' && ch <= 'V')
return 8;
if(ch >= 'W' && ch <= 'Y')
return 9;
return 0;
}
public:
void phonematch(int n, vector <string> str)
{
memset(exchange, 0, sizeof(exchange));
memset(resultNum, 0, sizeof(resultNum));
int exchangeNum = 0;
int maxNum = 1;
int leastIndex = -1;
int leastValueA = 999;
int leastValueB = 9999;
for(int i = 0; i < SZ(str); i++)
{
int temp[2] = {0,0};
int count = 0;
int value = 0;
int length = LN(str[i]);
int loc = 0;
int k = 0;
int flag = 0;
//format the phone number
for(int j = 0; j < length; j++)
{
char ch = str[i].at(j);
if(ch == '-')
continue;
if(ch >= '0' && ch <= '9' )
{
value *= 10;
value += (ch -'0');
count++;
}
else if(ch >= 'A' && ch <= 'Z' )
{
value *= 10;
int result = exchangeChar(ch);
if(result == 0)
{
cout << "error!";
return;
}
value += result;
count++;
}
else
{
cout << "error!";
return;
}
if(count == 3)
{
temp[loc] = value;
value = 0;
count = -1;
loc++;
}
}
//count the times
for(k = 0; k < exchangeNum; k++)
{
if((temp[0] == exchange[k][0]) && (temp[1] == exchange[k][1]))
{
flag = 1;
resultNum[k]++;
}
}
if(flag == 0)
{
exchange[exchangeNum][0] = (int)temp[0];
exchange[exchangeNum][1] = (int)temp[1];
resultNum[exchangeNum] = 1;
exchangeNum++;
}
}
//show the result
for(int i = 0; i < exchangeNum; i++)
{
if(maxNum < resultNum[i])
maxNum = resultNum[i];
}
if(maxNum == 1)
{
cout << "No duplicates.";
return;
}
//show as ascent
for(int k = 0; k < exchangeNum; k++)
{
for(int i = 0; i < exchangeNum; i++)
{
if(resultNum[i] > 1)
{
if(exchange[i][0] < leastValueA || ((exchange[i][0] == leastValueA) && (exchange[i][1] <
leastValueB)))
{
leastValueA = exchange[i][0];
leastValueB = exchange[i][1];
leastIndex = i;
}
}
}
if(leastIndex != -1)
{
cout << exchange[leastIndex][0] << "-" << exchange[leastIndex][1] << " " <<resultNum[leastIndex] <<
endl;
resultNum[leastIndex] = 1;
leastIndex = -1;
leastValueA = 999;
leastValueB = 9999;
}
}
}
};
int main(int argc, char* argv[])
{
int n;
cin >> n;
string temp;
vector <string> str;
getline(cin,temp);
for(int i = 0; i < n; i++)
{
cin.clear();
getline(cin,temp);
str.insert(str.end(),temp);
}
phoneMatch* ptr = new phoneMatch;
ptr->phonematch(n,str);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator