Saicode.com: Yoder Test

Title description:

兰博和提莫闲聊之后,回归到了他们的正题,约德尔人的未来。

说起约德尔人的未来,黑默丁格曾经提出了一个约德尔测试,将约德尔人的历史的每个阶段都用一个字符表达出来。(包括可写字符,不包括空格。)。然后将这个字符串转化为一个01串。转化规则是如果这个字符如果是字母或者数字,这个字符变为1,其它变为0。然后将这个01串和黑默丁格观测星空得到的01串做比较,得到一个相似率。相似率越高,则约德尔的未来越光明。

请问:相似率为多少?

 

Input

 

Each set of input data consists of two lines. The first line is a character string about the history of Yoder, and the second line is the character string obtained by Hemmerdinger observing the starry sky.

(The length of the two strings is equal, the length of the string is not less than 1 and not more than 1000.)

 

Sample input
 

@!% 12dgsa

010111100

Output

 

One line is output, and the similarity rate is output on this line. Expressed as a percentage. (The similarity rate is the number of the same characters / total number of the same characters, accurate to two digits after the decimal point. Printf ("%%"); output a%.)

 

Sample output

 

66.67%

 

Time limit C / C ++ language: 1000MS Other languages: 3000MS

Memory limit C / C ++ language: 65536KB Other languages: 589824KB

 

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//@!%12dgsa
//010111100
float  yodelTest(string s1, string s2){
    int num = 0;
    int len = s1.length();
    for (int i = 0; i < len; ++i) {
        if(s1[i] == s2[i]) num++;
    }
    return float(num) / float(len) * 100;
}

string strConvert(string s){
    for (int i = 0; i < s.length(); ++i) {
        if(isalnum(s[i]))
            s[i] = '1';
        else
            s[i] = '0';
    }
    return s;
}

int main() {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    s1 = strConvert(s1);
    cout<<fixed<<setprecision(2) << yodelTest(s1, s2) << "%" << endl;
    return 0;
}

 

Published 34 original articles · Like 10 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/weixin_41111088/article/details/104730275