Match Finder (FLAME)

As I was going through the Infosys given code file, I found one program to be interesting. It really remind me my primary level days and it is really helpful to learn some of the string operation. So here I am providing the code for “match finder” based on the word “FLAME”. I hope it will be useful to you too.

Code Goes Like This:

/**
 *
 * @author Prashant
 */
public class MatchFinder {
    public String matchfinder(String str1, String str2) {
        int alp1[]=new int[65];
        int alp2[]=new int[97];
        String result = "";
        int k = 0;
        int count = 6;
        char c1[] = str1.toCharArray();
        for (int i = 0; i = 65) && ((int) c1[i] = 97) && ((int) c1[i] <= 122))
                alp1[(int) c1[i] -97]++;
        }
        char c2[] = str2.toCharArray();
        for (int i = 0; i = 65) && ((int) c2[i] = 97) && ((int) c2[i] <= 122))
            alp2[(int) c2[i] -97]++;
        }
        int t;
        boolean flag = true;
        for (int i = 0; i < 26; i++) {
            if (alp1[i] != alp2[i])
               flag = false;
            t = 0;
            t = alp1[i] -alp2[i];
            if (t  1; f++) {
            if (f == 6)
            f = 0;
            if (flames[f] != 'Z') {
                if (c == k) {
                   flames[f] = 'Z';
                   c = 1;
                   count--;
                } else
                c++;
            }
         }
        if (flames[0] == 'F')
            return "FRIEND";
        if (flames[1] == 'L')
            return "LOVE";
        if (flames[2] == 'A')
            return "AFFECTION";
        if (flames[3] == 'M')
            return "MARRIAGE";
        if (flames[4] == 'E')
            return "ENEMY";
        if (flames[5] == 'S')
            return "SISTER";
        return result;
    }
    public static void main(String a[]) {
        String k1 = "Prashant";
        String k2 = "Shruti P";
        String val = new MatchFinder().matchfinder(k1, k2);
        System.out.println(val);
    }
}

Output:
FRIEND

Advertisements

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: