问答题
题1:
题2:
题3:
编程题
题1:字符串计数
求字符串的个数,而这个字符串所满足的条件是字典序在 s1-s2之间的且长度在 len1 - len2 之间
例,输入:ab ce 1 2 输出:56
解题思路
循环接收收入,保证所有测试用例可以验证到
将 s1
和 s2
补齐到 26
位,因为在字典序列中 s1
比 s2
靠前,因此 s1
后序所有位补 'a'
,s2
后补 'z'
+1
确认 s1
和 s2
两个字符串每个字符位置上的差值
确认 len1
和 len2
之间不同字符的个数
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main() {
string s1, s2;
int len1, len2;
while (cin >> s1 >> s2 >> len1 >> len2) {
//字符串补齐到len2的长度
s1.append(len2 - s1.size(), 'a');
s2.append(len2 - s2.size(), (char)('z' + 1));
//确认s2 和 s1 每一个位置上的差值
vector