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 |
一千万 int 型数组会 memory limit exceed 吗?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator