刷题记录4

1.编程题:https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50?tpId=37&tqId=21233&tPage=1&rp=&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking

num = input()
chars = []
for i in range(len(num)):
    if num[i] not in chars and 0 <= ord(num[i]) <= 127:
        chars.append(num[i])
print(len(chars))

2.编程题:https://www.nowcoder.com/questionTerminal/440f16e490a0404786865e99c6ad91c9?f=discussion python一行解法。

print(bin(int(input())).count("1"))

3.友元函数是独立于当前类的外部函数。
4.抽象类和接口都用于抽象。接口中定义的变量必须给其初值,实现类中不能重新定义,也不能改变其值。
5.编程题:https://www.nowcoder.com/test/question/340e0d941b614a12a661d8d0285decf3?pid=17800753&tid=26653324

#include<string>
#include<iostream>
using namespace std;
bool isMatch(string str, string sub,int &res){
    int lst = str.length();
    int lsb = sub.length();
    int temp = res;
    bool flag = false;
    if (lsb == 0)
        return true;
    else if (lst == 0)
        return false;
    else if (str[0] == sub[0]){
        res++;
        return isMatch(str.substr(1), sub.substr(1), res);
    }
    else if (sub[0] == '?'){
        temp = res;
        res++;
        flag = isMatch(str.substr(1), sub.substr(1), res);
        if (flag == false && lst >= 2){
            res = temp + 2;
            flag = isMatch(str.substr(2), sub.substr(1), res);
        }
        if (flag == false && lst >= 3){
            res = temp + 3;
            flag = isMatch(str.substr(3), sub.substr(1), res);
        }
        return flag;
    }
    else
        return false;
}
int main(){
    string str;
    string sub;
    cin >> str >> sub;
    int res = 0;
    if (isMatch(str, sub, res)){
        cout << res;
    }
    else{
        cout << -1;
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务