直接アドレス指定テーブルを実装するC++プログラム
これは、直接アドレス指定テーブルを実装するためのC++プログラムです。直接アドレス指定テーブルは、各要素にユニバーサルセットS ={0、1 、.から引き出されたキーがある場合に使用されます。 。 。 、n − 1}ここで、nは大きすぎず、各キーは一意です。迅速な挿入、検索、削除操作を容易にします。
関数と擬似コード
Begin insert(): Take the table variables word and key as argument. T[ x.key ] = x, where x is a value of key. delete(): Take the table variables word and key as argument. T[ x.key ] = tab(0,” ”) search(): Return T[key] Endを返します
例
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
struct tab { //declaration of variables of the table.
string word;
int key;
tab()
{}
tab( int k, string w ) //constructor to initialize the
variable. {
word=w;
key = k;
}
};
void INSERT( tab T[], tab x ) {
T[ x.key ] = x;
}
void DELETE( tab T[], tab x ) {
T[ x.key ] = tab(0, "");
}
tab SEARCH( tab T[], int key ) {
return T[ key ];
}
int main() {
int i, k, c;
string str;
tab T[65536]; //initialize size of the table.
tab x;
for(i = 0; i < 65536;i++)
T[i] = tab(0,"");
while (1) {
cout<<"1.Insert element into the key"<<endl;
cout<<"2.Delete element from the table"<<endl;
cout<<"3.Search element into the table"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>c;
switch(c) {
case 1: {
string str1 = "";
cout<<"Enter the key value: ";
cin>>k;
cout<<"Enter the string to be inserted: ";
cin.ignore();
getline(cin, str);
INSERT(T, tab(k, str));
break;
}
case 2:
cout<<"Enter the key of element to be deleted: ";
cin>>k;
x = SEARCH(T, k);
DELETE(T, x);
break;
case 3:
cout<<"Enter the key of element to be searched: ";
cin>>k;
x = SEARCH(T, k);
if (x.key == 0) {
cout<<"No element inserted at the key"<<endl;
continue;
}
cout<<"Element at key "<<k<<" is-> ";
cout<<"\""<<x.word<<"\""<<endl;
break;
case 4:
exit(1);
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
} 出力
1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 1 Enter the string to be inserted: hi 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 2 Enter the string to be inserted: tutorials 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 3 Enter the string to be inserted: point 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 1 Element at key 1 is-> "hi" 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 4 No element inserted at the key 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 2 Enter the key of element to be deleted: 1 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 1 No element inserted at the key 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 4
-
アフィン暗号を実装するためのC++プログラム
アフィン暗号では、アルファベットの各文字が同等の数値にマップされ、モノアルファベットの換字式暗号の一種です。暗号化は単純な数学関数を使用して行われ、文字に変換されます。 サイズmのアルファベットの文字は、最初に、アフィン暗号で0…m-1の範囲の整数にマップされます。 アフィン暗号の「キー」は、aとbの2つの数字で構成されます。 aはmに対して互いに素になるように選択する必要があります。 暗号化 整数を変換するには、各平文文字が対応するモジュラー演算を使用して、暗号文文字に対応する別の整数に変換します。 1文字の暗号化機能は E ( x ) = ( a x + b ) mod m modu
-
シーザー暗号を実装するC++プログラム
これは、平文の各文字が別の文字に置き換えられて暗号文を形成するモノアルファベット暗号です。これは、換字式暗号方式の最も単純な形式です。 この暗号システムは、一般にシフト暗号と呼ばれます。コンセプトは、各アルファベットを、0から25の間の固定数で「シフト」された別のアルファベットに置き換えることです。 このタイプのスキームでは、送信者と受信者の両方がアルファベットをシフトするための「秘密のシフト番号」に同意します。この0から25までの数字が暗号化の鍵になります。 「シーザー暗号」という名前は、「3シフト」が使用されている場合のシフト暗号を表すために使用されることがあります。 プロセス