vendredi 26 février 2021

Having trouble figuring out how to output only the largest output of a function

I am writing a code that uses a function I made to calculate the likeness scores between strings of numbers and letters which are supposed to represent playing cards. For example the string "H8C6D6" represents 8 of hearts, 6 of clubs, and 6 of diamonds. Anyway, the new function I'm writing takes a string whose length is greater than or equal to the golden sequence (aka the string it is being compared to in order to calculate the likeness score) and calculates the likeness score for all the substrings that are of equal length to the golden sequence. The problem I am running into is that I am only supposed to output the largest likeness score, but instead all of the likeness scores are being outputted. I'm not sure how to fix this. I have tried functions such as fmax(), but they have not worked for me. Any help would be greatly appreciated.

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;


double calcLikenessScore(string seq1, string seq2)
{
    int n=seq1.length(); //length of seq1
    int m=seq2.length(); //length of seq2
    if(n != m) //if lengths of both the strings are not equal then we return -1
    return -1;
    int match_cards = 0; //variable to store the matching cards 
    int bonus = 0; //variable to store the bonus
    for(int i = 0; i < n; i += 2)
    {
        if(seq1[i] == seq2[i]) //if the suit of both the sequences is equal
        {
            match_cards++; //matching cards is incremented by 1
            if(seq1[i + 1] == seq2[i + 1]) //if the rank of both sequences is also equal 
            {
                bonus++; //bonus is incremented by 1.
            }
        }
    }
    int total_cards = n / 2; //total cards are length/2.
    double likeness_score = double(match_cards) / double(total_cards) + bonus; //calculating 
likeness_score 
    return likeness_score; 
}


double bestLikenessScore(string seq1 , string gold_seq)
{
    int n = seq1.length(); //Length of sequence 1
    int m = gold_seq.length(); //Length of golden sequence
    if (n < m) //If the length of sequence 1 is not greater than or equal to the golden 
sequence, then it will return -1
    return -1;
    int i;
    for (int i; i < n; i += 2)
    {
        string str1 = seq1.substr(i , m); //String that holds substring values of seq1
        double d = calcLikenessScore(str1 , gold_seq); //Function to calculate Likeness 
scores of substrings
        if (str1.length() == m)
        {
            cout << d << endl; //Outputs likeness scores, but how can I make it so it will 
only output the largest value
        }
    }
    return 0;
}


int main()
{
    string s1; //First string to test; should be of greater or equal length to s2(gold_seq)
    string s2; //Golden Sequence
    cout << "enter first string: " << endl;
    cin >> s1;
    cout << "enter second string: " << endl;
    cin >> s2;
    double c = bestLikenessScore(s1 , s2); //Runs all substrings through calcLikenessScore() 
function, and outputs the lkeness scores of substrings
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire