0% found this document useful (0 votes)
84 views

May Algorithm Challenge

This document describes a Java program that performs the FLAMES algorithm to determine the relationship between two people based on their names. It takes the two names as input, eliminates matching characters, counts the total remaining characters, performs calculations on that count to select a letter from the string "FLAMES", and outputs the corresponding relationship label. The program initializes fields, gets the names from text boxes, performs the preprocessing, calculations, relationship determination, and displays the output.

Uploaded by

prabhusct
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

May Algorithm Challenge

This document describes a Java program that performs the FLAMES algorithm to determine the relationship between two people based on their names. It takes the two names as input, eliminates matching characters, counts the total remaining characters, performs calculations on that count to select a letter from the string "FLAMES", and outputs the corresponding relationship label. The program initializes fields, gets the names from text boxes, performs the preprocessing, calculations, relationship determination, and displays the output.

Uploaded by

prabhusct
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

MAY ALGORITHM CHALLENGE-2010

/**
*
* @author VIP
*/

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*;

/*
<APPLET CODE="flames" width=500 height=500>
</APPLET>
*/

public class flames extends Applet implements ActionListener{

char ch;
String msg,s,d;
StringBuffer b;
int count,ct,i,j,n,m,cur,len;
TextField st,dt,re;

public void init()


{

Label stl=new Label("Your Name:");


st=new TextField(25);
add(stl);
add(st);

Label dtl=new Label("Partner Name:");


dt=new TextField(25);
add(dtl);
add(dt);

Button go=new Button("MATCHING");


add(go);
re=new TextField(10);
add(re);
go.addActionListener(this);

}
public void actionPerformed(ActionEvent ae)

repaint();

public void paint(Graphics g) {


// TODO code application logic here

// INITIALIZATION

msg=d=s="";
ch=' ';
len=cur=0;
count=n=m=0;

s=st.getText();
d=dt.getText();
n=s.length();
m=d.length();

//ELIMINATING SIMILAR ALPHABET IN BOTH NAMES.

for(i=0;i<n;i++)
{
j=d.indexOf(s.charAt(i));
if(j!=-1)
{
char c=d.charAt(j);
s=s.replaceFirst(""+c,"_");
d=d.replaceFirst(""+c,"_");

} //end of loop

//COUNT TOTAL CHARS

for(i=0;i<n;i++)
if(s.charAt(i)!='_')
count++;
for(i=0;i<m;i++)
if(d.charAt(i)!='_')
count++;

ct=count;

// FLAMES CALCULATION

b=new StringBuffer("FLAMES");

for(i=0;i<5;i++)
{
cur=cur+ct;
len=b.length();
if(cur>len)
while(cur>len)
cur-=len;
cur--;
ch=b.charAt(cur);
b.deleteCharAt(cur); // REMOVE CHECKED CHARS

}//end of loop

ch=b.charAt(0);
if(ch=='F') msg="FRIEND";
if(ch=='L') msg="LOVE";
if(ch=='A') msg="AFFECTION";
if(ch=='M') msg="MARRIAGE";
if(ch=='E') msg="ENEMY";
if(ch=='S') msg="SISTER";

g.drawString(" RELATIONSHIP WAS: "+msg,200,100);


re.setText(msg);

}//END OF PAINT

}// END OF CLASS

You might also like