微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法弄清楚如何仅输出函数的最大输出

如何解决无法弄清楚如何仅输出函数的最大输出

我正在编写一个代码,它使用我制作的一个函数来计算应该代表扑克牌的数字和字母字符串之间的相似度分数。例如,字符串“H8C6D6”代表 8 个红心、6 个俱乐部和 6 个钻石。无论如何,我正在编写的新函数采用一个长度大于或等于黄金序列的字符串(也就是为了计算相似度分数而与之进行比较的字符串),并计算所有子串的相似度分数与黄金序列等长。我遇到的问题是我只应该输出最大的相似度分数,而是输出所有相似度分数。我不知道如何解决这个问题。我尝试过 fmax() 等函数,但它们对我不起作用。任何帮助将不胜感激。

#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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。