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

Re:今天可真是郁闷呀,我将数组s降到30才不会超内存,33还超,可是 s不变,将que降到10000还超,40000的int型数组难道没有3个char型

Posted by xiaol at 2005-10-17 22:31:24 on Problem 1002
In Reply To:一千万 int 型数组会 memory limit exceed 吗? Posted by:xiaol at 2005-10-17 21:50:17
> #include <iostream>
> #include <cstdlib>
> using namespace std;
> int a[10000000]={0};
> int que[50001];
> int cmp(const void *a,const void *b) {
>     return *(int *)a-*(int *)b;
> }
> int main() {
>     char s[100];
>     int n,i;
>     int k;
>     int num;
>     int temp;
>     cin>>n;
>     cin.ignore();
>     int r=0;
>     for(i=0;i<n;i++) {
>         scanf("%s",s);
>         num=0;
>         for(k=0;s[k]!='\0';k++) {
>             if((s[k]>='A' && s[k]<='C') || s[k]=='2') num=num*10+2;
>             else if((s[k]>='D' && s[k]<='F') || s[k]=='3') num=num*10+3;
>             else if((s[k]>='G' && s[k]<='I') || s[k]=='4') num=num*10+4;
>             else if((s[k]>='J' && s[k]<='L') || s[k]=='5') num=num*10+5;
>             else if((s[k]>='M' && s[k]<='O') || s[k]=='6') num=num*10+6;
>             else if(s[k]=='P' || s[k]=='R' || s[k]=='S' || s[k]=='7') num=num*10+7;
>             else if((s[k]>='T' && s[k]<='V') || s[k]=='8') num=num*10+8;
>             else if((s[k]>='W' && s[k]<='Y') || s[k]=='9') num=num*10+9;
>             else if(s[k]=='1') num=num*10+1;
>             else if(s[k]=='0') num=num*10;
>         }
>         ++a[num];
>         if(a[num]==2) {
>             que[r]=num;
>             ++r;
>         }
>     }
>     
>     if(r==0){
>         cout<<"No duplicates."<<endl;
>     } 
>     else {   
>     qsort(que,r,sizeof(que[0]),cmp);
>     for(i=0;i<r;i++) {
>         temp=que[i]; 
>         printf("%c",temp/1000000+'0');
>         temp=temp%1000000;
>         printf("%c",temp/100000+'0');
>         temp=temp%100000;
>         printf("%c",temp/10000+'0');
>         temp=temp%10000;
>         printf("-%c",temp/1000+'0');
>         temp=temp%1000;
>         printf("%c",temp/100+'0');
>         temp=temp%100;
>         printf("%c",temp/10+'0');
>         temp=temp%10;
>         printf("%c",temp+'0');
>         printf(" %d\n",a[que[i]]);
>     }
> }    
>     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