⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sim.txt

📁 C精彩编程百例源码
💻 TXT
字号:
// myclass18.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iostream>

using namespace std;


int eq_count(int *a,int *b,int m,int n)
{
	int index_a,index_b;
	int count;

	count=index_a=index_b=0;
	while(index_a<m&&index_b<n)
		if(a[index_a]<b[index_b])
			index_a++;
		else if(a[index_a]>b[index_b])
			index_b++;
		else 
			count++,index_a++,index_b++;
		return count;
}


void swap(int &a,int &b)
{
	a=a^b;
	b=a^b;
	a=a^b;
}

void Restore(int *tree, int s, int m)
{
	int j;
	int x=tree[s];
	for(j=s+s;j<=m;j+=j)
	{if(j<m&&(tree[j]<tree[j+1])) ++j;
	if(!(x<tree[j]))   break;
	tree[s]=tree[j];s=j;}
	tree[s]=x;
}

void HeapSort(int *r, int n)
{
	for(int i=(n-1)/2;i>=0;i--)
		Restore(r,i,n-1);
	for(i=n-1;i>0;i--)
	{
		int temp=r[0];
		r[0]=r[i];
		r[i]=temp;
		//swap(r[0],r[i]);
			Restore(r,0,i-1);
			//for(int t=0;t<n;t++)
				//cout<<r[t]<<endl<<endl;
	}
}



float hash_str(string a,string b)
{
	int i,j;
	int pri_hash,hash,count;
	int m=a.length(),n=b.length();
	int *pa=new int[m-1],*pb=new int[n-1];

	for(i=0;i<m-1;i++)
	{
		pri_hash=(int)a[i]*32+(int)a[i+1]*1024;
		hash=pri_hash%676;
		pa[i]=hash;
	}

		for(j=0;j<n-1;j++)
	{
		pri_hash=(int)b[j]*32+(int)b[j+1]*1024;
		hash=pri_hash%676;
		pb[j]=hash;
	}

		
				for(i=0;i<m-1;i++)
			cout<<pa[i]<<endl;

		for(j=0;j<n-1;j++)
			cout<<pb[j]<<endl;

		HeapSort(pa,m-1);
		HeapSort(pb,n-1);

				for(i=0;i<m-1;i++)
			cout<<pa[i]<<endl;

		for(j=0;j<n-1;j++)
			cout<<pb[j]<<endl;

		count=eq_count(pa,pb,m-1,n-1);
		cout<<count<<endl;
		float sim=(float)count/(m+n-2-count);
		return sim;

}


int main(int argc, char* argv[])
{
	//string c="abcd",b="abce";
    //hash_str(c,b);

	int *a=new int[5];
	a[0]=6;
			a[1]=5;
				a[2]=4;
					a[3]=3;
						a[4]=2;
	HeapSort(a,5);
	
	for(int i=0;i<5;i++)
		cout<<a[i]<<endl;
	//int b[5]={6,5,4,3,2};
	//HeapSort(b,5);
	//for(i=0;i<5;i++)
		//cout<<b[i]<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -