当前位置:网站首页>String count (convert to base)
String count (convert to base)
2022-04-21 13:39:00 【4nc414g0n】
String count
Topic link
Title Description:
Find the dictionary order in s1 and s2 Between , The length is in len1 To len2 Number of strings , result mod 1000007. Data range :s1( The length is less than 50),s2( The length is less than 50),len1( Less than 50),len2( Greater than len1, Less than 50) Be careful : There are many groups of input
Input :
Each set of data includes s1( The length is less than 50),s2( The length is less than 50),len1( Less than 50),len2( Greater than len1, Less than 50)
ab ce 1 2
Output :
56
Ideas:
- Because it comes from the meaning of the title, it is a lowercase letter a~z, common 26 position , Think of it as 26 Binary operation
- First step , Use append Complete the two strings to len2, It's easy to compare ,s1 Full complement ‘a’, s2 Full complement char(‘z’+1), Define another record 26 An array of hexadecimal digits arr, Subscript to be 0 The number of digits is the largest
- i from 0 Start to len2 The current comparison between the two strings is the i position , Get the characters at the corresponding positions of the two strings in the loop arr Array ( Be careful : Negative numbers need to borrow from the high position ,
The code here needs to be improved)- i from len1 Start to len2, The number of representative digits is i A string that satisfies the conditions , for example arr={2,3,1},
The length is 1 The string of is2*260The length is 2 The string of is2*261+3*260The length is 3 The string of is2*262+3*261+1*260- Note that the last string does not count result–
The code is as follows :int main() { string s1, s2; int len1, len2; while (cin >> s1 >> s2 >> len1 >> len2) { // A string containing only lowercase letters can be regarded as 26 Hexadecimal number system // take s1 and s2 Lengthen to len2 length s1.append(len2 - s1.size(), 'a'); s2.append(len2 - s2.size(), (char)('z' + 1)); // confirm s1 and s2 The difference between the two strings at each position vector<int> arr; for (int i = 0; i < len2; ++i) { if(s2[i] - s1[i]<0) { arr.back()-=1; arr.push_back(s2[i] - s1[i]+26); } else arr.push_back(s2[i] - s1[i]); } // confirm len1 and len2 The number of different strings that can be formed between int result = 0; for (int i = len1; i <= len2; ++i) for (int k = 0; k < i; ++k) result += arr[k] * pow(26, i - 1 - k); // All strings do not end with s2 Oneself , All the final reduction is 1 cout << result << endl; } return 0; }
版权声明
本文为[4nc414g0n]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211217327916.html
边栏推荐
- Suggestion: Alt + X marks the marked area. Can I cancel the marking?
- List stores map values
- 如何在Centos下卸载OpenJDK,安装Oracle JDK
- Installing and configuring canal
- 2022 supervision engineer contract management exercises and answers
- 北京大学ACM Problems 1008:Maya Calendar
- How to recover if U disk data is lost? U disk data recovery, two schemes completed
- 2021-2022 Guangdong Vocational College Students' professional skills competition
- Peking University ACM problems 1010: stamps
- Technology giants compete to enter, who can become the "number one player" of the meta universe?
猜你喜欢

leetcode:无数个面额的硬币得到amount的选法(dp)

3-4Dom形XSS详解以及演示

Last online class can be "distracted" by AI analysis. Intel's emotional detection AI is on fire

Small and medium-sized manufacturing enterprises transformation capacity-building sharing

Accounting practice exercises and answers for the 2022 primary accounting title examination

If the field lines are the same, they will be merged into another field SQL statement?

u盘数据丢失了怎么恢复?u盘数据恢复,2个方案完成

Réaliser l'affichage aléatoire de l'étiquette, de la taille de la police et de la couleur

Basic practice questions and answers of economic law in 2022 primary accounting title examination

Exercise questions and answers of basic theories and relevant laws and regulations in 2022 supervision engineer examination
随机推荐
Wanzi dry goods! Help you deeply master the knowledge points of "light and shadow" in design (Part 2)
专家系统实例及其骨架系统
Industry video super resolution new benchmark, Kwai & Dalian research, boarded CVPR 2022
Small and medium-sized manufacturing enterprises transformation capacity-building sharing
實現隨機標簽,字體大小、顏色隨機顯示
【csnote】db异常(冗余数据、修改异常、删除异常、插入异常)
leetcode:513. 找树左下角的值【简单bfs找每层第一个】
Mysql 驱动为什么要依赖 protobuf
What about first-class insurance? Is there a charge? What are the waiting requirements?
What kind of comfortable sports earphones are recommended
Go language file operation
Q: How to change the number of appendix in the paper with the text.
JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
Peking University ACM problems 1010: stamps
【数字信号处理】线性常系数差分方程 ( 根据 “ 线性常系数差分方程 “ 与 “ 边界条件 “ 确定系统是否是 “ 线性时不变系统 “ 案例 | 使用递推方法证明 )
完成数亿元融资后,毫末智行计划超百城落地城市智能驾驶产品
北京大学ACM Problems 1010:STAMPS
Access的BOM开发(3)BOM展开
Nmap usage
Mysql 浅析行锁如何减少冲突提高性能