Membuat AnagRam

#include <iostream>
#include <conio.h>

int main(int argc, char *argv[])
{
char x[500], y[500];
cout << “Masukkan Kata Pertama :  “;cin.getline (x,500);
cout<<endl;
cout << “Masukkan Kata Kedua   :  “;cin.getline (y,500);
cout<<endl; cout<<endl; cout<<endl; cout<<endl; cout<<endl;
char a[] = {“abcdefghijklmnopqrstuvwxyz”};
char b[] = {“ABCDEFGHIJKLMNOPQRSTUVWXYZ”};
int c[26] = {0};
int d[26] = {0};
int e = (int)strlen(x);
int f = (int)strlen(y);
if (e == f)
{
for (int i = 0; i < e; i++)
{
for (int j = 0; j < 26; j++) {
if ((x[i] == a[j]) || (x[i] == b[j])) {
c[j] += 1;
}

if ((y[i] == a[j]) || (y[i] == b[j])) {
d[j] += 1;
}
}
}
bool identical = true;
for (int i = 0; i < 26; i++) {
if (c[i] != d[i]) {
identical = false;
}
}
if (identical) { cout << “Kata Yang Anda Masukkan ANAGRAM” << endl; }
else { cout << “Kata Yang Anda Masukkan BUKAN ANAGRAM” << endl; }
}
else { cout << “Kata Yang Anda Masukkan BUKAN ANAGRAM” << endl; }

getch ();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: