刷题记录4
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; }