| ||||||||||
| 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 | |||||||||
Re:提交多次还是WA,求大神指点迷津In Reply To:提交多次还是WA,求大神指点迷津 Posted by:38872980 at 2012-11-29 14:20:10 > #include <iostream>
> #include <stdlib.h>
> #include <math.h>
>
> using namespace std;
>
> const int MAX = 200000;
>
> void TransToNum(const char* str, int *a)
> {
> for (int i = 0 ; i < strlen(str); i++)
> {
> if ('-' == str[i])
> {
> continue;
> }
> else if (('0' <= str[i]) && ('9' >= str[i]))
> {
> *a = (*a)*10 + static_cast<int>(str[i] - '0');
> }
> else
> {
> switch(str[i])
> {
> case 'A':
> case 'B':
> case 'C':
> *a = (*a)*10 + 2;
> break;
> case 'D':
> case 'E':
> case 'F':
> *a = (*a)*10 + 3;
> break;
> case 'G':
> case 'H':
> case 'I':
> *a = (*a)*10 + 4;
> break;
> case 'J':
> case 'K':
> case 'L':
> *a = (*a)*10 + 5;
> break;
> case 'M':
> case 'N':
> case 'O':
> *a = (*a)*10 + 6;
> break;
> case 'P':
> case 'R':
> case 'S':
> *a = (*a)*10 + 7;
> break;
> case 'T':
> case 'U':
> case 'V':
> *a = (*a)*10 + 8;
> break;
> case 'W':
> case 'X':
> case 'Y':
> *a = (*a)*10 + 9;
> break;
> default:
> return;
> }
> }
> }
> }
> int cmp(const void*a,const void*b)//快排自定义cmp
> {
> return *(int*)a-*(int*)b;
> }
> int main()
> {
> int n;
> int m;
> int j;
> char strInput[256];
> int result[MAX];
> bool hasNum;
>
> m = 0;
> hasNum = false;
> memset(result, 0, sizeof(int)*MAX);
>
> cin>>n;
> for (int i=0; i<n; i++)
> {
> cin>>strInput;
> TransToNum(strInput, &result[m++]);
> }
> qsort(result,n,sizeof(int),cmp);
> for(size_t i=0; i<n-1; i++)
> {
> j = i;
> while(result[i] == result[i+1])
> {
> i++;
> }
> if (i != j)
> {
> cout<<result[i]/10000<<"-";
> cout<<result[i]%10000;
> cout<<" "<<i-j+1<<endl;
> hasNum = true;
> }
> }
> if (!hasNum)
> {
> cout<<"No duplicates."<<endl;
> }
> return 0;
> }
好乱,看不懂你的主函数。
> while(result[i] == result[i+1])
> {
> i++;
> }
i == n-2 and result[n-2] == result[n-1]
i == n-1 and result[n-1] == result[n] ?
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator