| ||||||||||
| 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:大牛们帮我看看程序,为什么是Runtime errorIn Reply To:大牛们帮我看看程序,为什么是Runtime error Posted by:se19880529 at 2010-05-11 01:28:05 > #include<iostream>
> #include<string>
> #include<string.h>
> #define MAX_COUNT 100000
> #define MAX_BUFF 20
> const char table[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','7','7','7','8','8','8','9','9','9'};
> using namespace std;
> struct list{
> list* pre;
> string buf;
> int num;
> list* next;
> };
> void initList(list* l){
> l->next=NULL;
> l->pre=l;
> };
> void insert(list* h,list* a){
> a->next = NULL;
> h->pre->next = a;
> a->pre=h->pre;
> h->pre=a;
> };
> list* merge(list* head,list* h,int num){
> initList(head);
> list* temp;
> for(int i=0;i<num-1;i++){
> if(h[i].next==NULL)continue;
> head->pre->next=h[i].next;
> h[i].next->pre=head->pre;
> head->pre=h[i].pre;
> }
> return head;
> };
> class Directory{
> unsigned int m_number,m_Max;
> string* m_buffer;
> public:
> Directory(int num=100):m_Max(num),m_number(0){
> if(num>MAX_COUNT)m_Max=MAX_COUNT;
> m_buffer=new string[m_Max];
> };
> string& regulize(string& a){
> char buf[MAX_BUFF],buf2[MAX_BUFF];
> strcpy(buf,a.c_str());
> for(int i=0,j=0;buf[i]!=0;i++)if(buf[i]!='-'){
> if(j==3)buf2[j++]='-';
> if(buf[i]>'9'||buf[i]<'0')buf2[j++]=table[((buf[i]-'A')>26)?(buf[i]-'a'):(buf[i]-'A')];
> else buf2[j++]=buf[i];
> }
> buf2[8]=0;
> return a=buf2;
> };
> bool Input(string a){
> if(m_number>=m_Max)return false;
> else{
> m_buffer[m_number]=regulize(a);
> m_number++;
> }
> return true;
> };
> void output(){
> string* temp=new string[m_number];
> unsigned int* num = new unsigned int[m_number];
> unsigned int count=0;
> bool exist=false;
> for(int i=0,j=0;i<m_number;i++){
> for(j=0,exist=false;j<count;j++){
> if(m_buffer[i]==temp[j]){
> exist=true;
> break;
> }
> }
> if(!exist)temp[count]=m_buffer[i],num[count++]=1;
> else num[j]++;
> }
> list List[10],listh,*tempp,*tempp2;
> initList(&listh);
> for(int i=0;i<count;i++){
> tempp=new list;
> tempp->buf=temp[i];
> tempp->num=num[i];
> insert(&listh,tempp);
> }
> for(int i=0;i<8;(++i)==4?i++:i){
> for(int j=0;j<10;j++)initList(&List[j]);
> for(tempp=listh.next;tempp!=NULL;){
> tempp2=tempp;
> tempp=tempp->next;
> insert(&List[tempp2->buf.c_str()[7-i]-'0'],tempp2);
> }
> merge(&listh,List,10);
> }
> bool duplicates=false;
> for(tempp=listh.next;tempp!=NULL;tempp=tempp->next){
>
>
> if(tempp->num>1){
> cout<<tempp->buf<<" "<<tempp->num;
> if(tempp->next!=NULL)cout<<endl;
> duplicates=true;
> }
> }
> if(!duplicates)cout<<"No duplicates.";
> for(tempp=listh.next;tempp!=NULL;tempp=tempp->next)delete tempp;
> delete[] temp;
> delete[] num;
> };
> ~Directory(){
> delete[] m_buffer;
> };
> };
>
> int main(){
> unsigned int count;
> cin>>count;
> string temp;
> Directory dc(count);
> for(int i=0;i<count;i++){
> cin>>temp;
> dc.Input(temp);
> };
> dc.output();
> return 0;
> }
>
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator