Скачиваний:
34
Добавлен:
10.05.2014
Размер:
3.9 Кб
Скачать
#include <iostream>
#include <string.h>
using namespace std;

int hash_calc_sv2(const char x[], const int size)
{
    cout<<x<<" ";
    int StringLength,HashKey,i,tmp,k;
    StringLength=strlen(x); //Начало вычисления ключа
    HashKey=0;
    if (StringLength%2==0) //Чётный случай
    {
        cout<<"   (even) ";
        for (i=0; i<StringLength; i=i+2)
        {
            tmp=x[i];
            tmp=tmp*1000;
            tmp=tmp+x[i+1];
            HashKey=HashKey+tmp;
        }
    }
    if (StringLength%2!=0) //Нечётный случай
    {
        cout<<"   (odd)  ";
        for (i=1; i<=StringLength; i=i+2)
        {
            tmp=x[i];
            tmp=tmp*1000;
            tmp=tmp+x[i+1];
            HashKey=HashKey+tmp;
        }
        k=0;
        k=x[0];
        HashKey=HashKey+k; cout<<x[0]<<" ";
    } //конец вычисления ключа
    //cout<<HashKey<<endl;
    return (HashKey);
}

int main(void)
{
    const int N=20;
    char st[N][16];
    int j,keyd[N],ht[N],ArrOfSin[N], StringLength,HashKey,i,tmp,k;
    strcpy(st[0],"zero");
    strcpy(st[1],"one");
    strcpy(st[2],"two");
    strcpy(st[3],"three");
    strcpy(st[4],"four");
    strcpy(st[5],"five");
    strcpy(st[6],"six");
    strcpy(st[7],"seven");
    strcpy(st[8],"eight");
    strcpy(st[9],"nine");
    strcpy(st[10],"ten");
    strcpy(st[11],"eleven");
    strcpy(st[12],"twelve");
    strcpy(st[13],"thirteen");
    strcpy(st[14],"fourteen");
    strcpy(st[15],"fifteen");
    strcpy(st[16],"sixteen");
    strcpy(st[17],"seventeen");
    strcpy(st[18],"eighteen");
    strcpy(st[19],"nineteen");

    for (j=0; j<N; j++)
    {
        cout<<st[j]<<" ";
		StringLength=strlen(st[j]); //Начало вычисления ключа
		HashKey=0;
		if (StringLength%2==0) //Чётный случай
		{
			cout<<"   (even) ";
			for (i=0; i<StringLength; i=i+2)
			{
				tmp=st[j][i];
				tmp=tmp*1000;
				tmp=tmp+st[j][i+1];
				HashKey=HashKey+tmp;
			}
		}
		if (StringLength%2!=0) //Нечётный случай
		{
			cout<<"   (odd)  ";
			for (i=1; i<=StringLength; i=i+2)
			{
				tmp=st[j][i];
				tmp=tmp*1000;
				tmp=tmp+st[j][i+1];
				HashKey=HashKey+tmp;
			}
			k=0;
			k=st[j][0];
			HashKey=HashKey+k; cout<<st[j][0]<<" ";
		} //конец вычисления ключа
		//cout<<HashKey<<endl;
		cout<<keyd[j]<<"\n";
    }
}





/*#include <iostream>
#include <string.h>

using namespace std;

int main(void)
{
    char alf[34][1],x[10];
    int i,key,StringLength,HashKey,tmp;
    
    strcpy(alf[1],"a");
    strcpy(alf[2],"b");
    strcpy(alf[3],"c");
    strcpy(alf[4],"d");
    strcpy(alf[5],"e");
    strcpy(alf[6],"f");
    strcpy(alf[7],"g");
    strcpy(alf[8],"h");
    strcpy(alf[9],"i");
    strcpy(alf[10],"j");
    strcpy(alf[11],"k");
    strcpy(alf[12],"l");
    strcpy(alf[13],"m");
    strcpy(alf[14],"n");
    strcpy(alf[15],"o");
    strcpy(alf[16],"p");
    strcpy(alf[17],"q");
    strcpy(alf[18],"r");
    strcpy(alf[19],"s");
    strcpy(alf[20],"t");
    strcpy(alf[21],"u");
    strcpy(alf[22],"v");
    strcpy(alf[23],"w");
    strcpy(alf[24],"x");
    strcpy(alf[25],"y");
    strcpy(alf[26],"z");
    
    for (i=1; i<=26; i++)
    {
		key=alf[i][0];
		cout<<alf[i][0]<<" "<<key<<"\n";
	}
	cout<<"\n";
	strcpy(x,"three");
	cout<<x<<"\n";
	
	StringLength=strlen(x); //Начало вычисления ключа
	HashKey=0;
	if (StringLength%2==0) //Чётный случай
	{
		for (i=0; i<StringLength; i=i+2)
		{
			tmp=x[i];
			tmp=tmp*1000;
			tmp=tmp+x[i+1];
			HashKey=HashKey+tmp;
		}
	}
	if (StringLength%2!=0) //Нечётный случай
	{
		cout<<"Н ";
		for (i=1; i<=StringLength; i=i+2)
		{
			tmp=x[i];
			tmp=tmp*1000;
			tmp=tmp+x[i+1];
			HashKey=HashKey+tmp;
		}
		HashKey=HashKey+x[0];
	} //конец вычисления ключа
	HashKey=HashKey%20;
	cout<<HashKey;
}
*/
Соседние файлы в папке old1