int main(void) { unsigned ind; binInit(); for (ind = 0; ind < MAX; ind++) binInsert(rand() % (MAX*2), ind); sort(); printf("Списъкът съдържа следните елементи: \n"); binPrint(); printf("\nТестване:\n"); performSearchTest(); return 0; }
int main(int argc,char*argv[]) { int w;//width int tmpVal=0; int tmpCnt=0; node tmpNode; node nd; int it[9]; while(true) { scanf("%d",&w); //printf("\n\n\nnew image %d\n",w); int dist[]={-w-1,-w,-w+1,-1,0,1,w-1,w,w+1}; int pixCnt=0; int idx=0; int outidx=0; if(w==0)break;//end //do-while build inList; scanf("%d %d",&tmpVal,&tmpCnt); while(tmpVal!=0||tmpCnt!=0) { //scanf("%d %d",&tmpVal,&tmpCnt); //printf("new node inList[%d] %d %d\n",idx,tmpVal,tmpCnt); tmpNode.val=tmpVal; tmpNode.cnt=tmpCnt; tmpNode.ofs=pixCnt; int k,l,m; nd.val=0;nd.cnt=-1; for(k=0;k<9;k++) { l=tmpNode.ofs+dist[k]; //printf("node%d pos: %d\n",tmpNode.ofs,l); m=tmpNode.ofs; // if((m<w&&k<3)||(m%w==0&&k%3==0)||(m%w==w-1&&k%3==2))continue; if(l<0)continue; //l=tmpNode.ofs+dist[k]; //nd.val=0; //nd.cnt=-1; nd.ofs=l; //printf("node%d pos: %d\n",tmpNode.ofs,l); //if(binSearch(outList,0,outidx,nd))printf("found\n"); if(!binInsert(outList,0,outidx,nd))outidx++; } //printf("this node val: %d cnt: %d ofs: %d\n",tmpNode.val,tmpNode.cnt,tmpNode.ofs); inList[idx++]=tmpNode;//inList.push_back(tmpNode); pixCnt+=tmpCnt; //idx++; scanf("%d %d",&tmpVal,&tmpCnt); } //test input is enough if(pixCnt%w!=0)printf("test pixCnt enough %d\n",pixCnt%w); //insert a watch dog in outList nd.ofs=pixCnt-w;//the left down element if(!binInsert(outList,0,outidx,nd))outidx++; nd.val=1000; nd.ofs=pixCnt; nd.cnt=-1; if(!binInsert(outList,0,outidx,nd))outidx++; int pos=0; //init it[] int i; /* for(i=0;i<outidx;i++) { printf("outList[%d].ofs=%d\n",i,outList[i].ofs); } */ int it1=0; for(i=0;i<9;i++) { // printf("init it[]\n"); // printf("%d Vs. %d\n",it1->ofs+it1->cnt,pos+dist[i]); while(inList[it1].ofs+inList[it1].cnt<=pos+dist[i])it1++; it[i]=it1; } int j; for(j=0;outList[j].ofs<pixCnt;j++) { pos=outList[j].ofs; //set it[] for(i=0;i<9;i++) { while(inList[it[i]].ofs+inList[it[i]].cnt<=pos+dist[i]&&it[i]<idx)it[i]++; } int maxDiff=0; for(i=0;i<9;i++) { if((pos<w&&i<3)||(pos>pixCnt-w&&i>5)||(pos%w==0&&i%3==0)||(pos%w==w-1&&i%3==2)||(i==4))continue; if(pos+dist[i]>=0&&pos+dist[i]<pixCnt)maxDiff=max(maxDiff,abs(inList[it[i]].val-inList[it[4]].val)); } //printf("pos: %d dif: %d\n",pos,maxDiff); outList[j].val=maxDiff; outList[j].cnt=0; } //outList[j].val=1000;//invaid value to use; //dump outList /* for(i=0;i<outidx;i++) { printf("test outList[%d] val:%d ofs:%d\n",i,outList[i].val,outList[i].ofs); } */ int it3=1,it2=0; printf("%d\n",w); while(it3<j+1) { //printf("it3=%d\n",it3); if(outList[it3].val!=outList[it2].val) { printf("%d %d\n",outList[it2].val,outList[it3].ofs-outList[it2].ofs); it2=it3; it3++; } else { it3++; } } printf("0 0\n"); } printf("0\n"); return 0; }
int main(int argc,char* argv[]) { int n; scanf("%d",&n); int i; char s[128]; char tmp[8]; node nodeVec[MAX]; int num=0; node nd; nd.count=1; for(i=0;i<n;i++) { scanf("%s",s); int j,k; for(j=0,k=0;j<strlen(s);j++) { if(s[j]>='A'&&s[j]<='Z') { tmp[k]=char2int(s[j])+'0'; k++; } else if(s[j]>='0'&&s[j]<='9') { tmp[k]=s[j]; k++; } else continue; } strcpy(nd.str,tmp); if(!binInsert(nodeVec,0,num,nd))num++; /* //dump node printf("\n\n\n"); int q; for(q=0;q<num;q++) { printf("%s %d\n",nodeVec[q].str,nodeVec[q].count); } */ } /* printf("final\n\n\n"); */ bool has=false; //if(num==0)printf("No duplicates.\n"); //else //{ for(i=0;i<num;i++) { //printf("test i %d\n",i); if(nodeVec[i].count>1) { has=true; printStr(nodeVec[i].str); printf(" %d\n",nodeVec[i].count); } } //} if(has==false)printf("No duplicates.\n"); return 0; }