当前位置: 首页 > news >正文

免费创建网站平台天津网站建设公

免费创建网站平台,天津网站建设公,推广公司服务内容,致力于网站开发维护学什么专业sql 算出下级销售总和Description: 描述#xff1a; This is a standard interview problem to check that the given string is a sum string or not using backtracking. 这是一个标准的面试问题#xff0c;用于检查给定的字符串是否为总和字符串或不使用回溯。 Problem…sql 算出下级销售总和Description: 描述 This is a standard interview problem to check that the given string is a sum string or not using backtracking. 这是一个标准的面试问题用于检查给定的字符串是否为总和字符串或不使用回溯。 Problem statement: 问题陈述 There is a string given to you. You have to find out whether the given string is a sum string or not. For a string 12345168213 if it goes like this, 123 45 168 45 168 213 then it is a sum string otherwise not. 有一个字符串给你。 您必须找出给定的字符串是否为求和字符串。 对于字符串“ 12345168213”如果这样 “ 123” “ 45” “ 168” “ 45” “ 168” “ 213” 则为求和字符串否则为非。 Input: Test case T T no. of strings we have to check. E.g. 3 12345168213 123581321 15643 Output: If the string is a sum-string then you have to print It is a sum string and, if it is not then you have to print It is not a sum string. Example 例 T3 Str 12345168213 123 45 168 45 168 213 It is a sum string Str 123581321 1 2 3 2 3 5 3 5 8 5 8 13 8 13 21 It is a sum string Str 15643 1 5 6 5 6 11 It is not a sum string Explanation with example 举例说明 To find out the actual length of the first two substrings is a problem of combination. We will solve the problem using the backtracking process. If we break the problem into sub-problems like, 找出前两个子串的实际长度是组合的问题。 我们将使用回溯过程解决问题。 如果我们将问题分解为子问题 Find out the length of the first sub-string. 找出第一个子字符串的长度。 Find out the length of the second sub-string. 找出第二个子字符串的长度。 Add the two strings. 添加两个字符串。 Check if the summation is the same as the next substring. 检查求和是否与下一个子字符串相同。 If yes, we will continue the process otherwise the string is not a sum string. 如果是我们将继续执行该过程否则该字符串不是求和字符串。 str.substring(i,j) str.substring(j1,k) str.substring(k1,l) str.substring(j1,k) str.substring(k1,l) str.substring(l1,m) Where, i, j, k, l, m is the position index on the substring of the string. 其中 i j k l m是字符串的子字符串的位置索引。 For the string 12345168213 对于字符串“ 12345168213” To find out the length of the first substring we will look for the all possible combination of the sub-string of the string from the starting index. 为了找出第一个子字符串的长度我们将从起始索引中查找该字符串的子字符串的所有可能组合。 1 , 12 , 123 , 1234 , 12345 , 123451 etc. “ 1” “ 12” “ 123” “ 1234” “ 12345” “ 123451”等 To find out the length of the second substring we will look for all possible combinations of the sub-string of the string from the last index of the first substring. 为了找出第二个子字符串的长度我们将从第一个子字符串的最后一个索引中查找该字符串的子字符串的所有可能组合。 Let the first index 123 then the all possible combinations are 4, 45, 451, 4516 etc. 假设第一个索引 “ 123”那么所有可能的组合都是“ 4” “ 45” “ 451” “ 4516”等。 After calculating the summation of the two sub-strings will also find out the length of the result and take the next sub-string who has a length equal to that length. 在计算完两个子字符串的总和后还将找出结果的长度并获取下一个长度等于该长度的子字符串。 If the two substrings are 123 and 45 after calculating the summation the result 168 we will calculate its length which is equal to 3 and take the next sub-string e.g. 168 如果两个子字符串分别是“ 123”和“ 45” 计算出结果“ 168”后我们将计算其长度等于3并取下一个子字符串例如“ 168” Both the resultant and the sub-string are the same therefore we will add up 45 and 168 and check with 213. 结果和子字符串都相同因此我们将“ 45”和“ 168”加起来并用“ 213”进行校验。 C implementation: C 实现 #include bits/stdc.h using namespace std; //adding the numbers string add(string str1, string str2) { int len1 str1.length(); int len2 str2.length(); int i 1; int carry 0; string str ; while ((len1 - i) 0 (len2 - i) 0) { int result (str1[len1 - i] - 0) (str2[len2 - i] - 0) carry; char ch (result % 10) 0; str ch str; carry result / 10; i; } while ((len1 - i) 0) { int result (str1[len1 - i] - 0) carry; char ch (result % 10) 0; str ch str; carry result / 10; i; } while ((len2 - i) 0) { int result (str2[len2 - i] - 0) carry; char ch (result % 10) 0; str ch str; carry result / 10; i; } if (carry 0) { char ch carry 0; str ch str; } return str; } bool checksumUtill(string str, int pos, int str1_len, int str2_len) { int n str.length(); int i str1_len, j str2_len; //if the total sum of the current position and //both the strings is greater than total length if (pos str1_len str2_len n) return false; //calculate the sum string s add(str.substr(pos, i), str.substr(pos i, j)); //if the next substring of posij is equals to the sum if (s str.substr(pos i j, s.length())) { if (pos i j s.length() n) return true; return checksumUtill(str, pos i, j, s.length()); } return false; } bool check_sum_string(string str) { if (str.length() 0) return false; int str1_len 1; int str2_len 1; int pos 0; //go for all the combinations for (int i 1; i str.length(); i) { for (int j 1; j str.length(); j) { if (checksumUtill(str, pos, i, j)) { return true; } } } return false; } int main() { int t; cout Test Case : ; cin t; while (t--) { string str; cout Enter the String : ; cin str; if (check_sum_string(str)) { cout It is a sum string\n; } else { cout It is not a sum string\n; } } return 0; } Output 输出量 Test Case : 3 Enter the String : 12345168213 It is a sum string Enter the String : 123581321 It is a sum string Enter the String : 15648 It is not a sum string 翻译自: https://www.includehelp.com/icp/find-out-the-sum-string.aspxsql 算出下级销售总和
http://www.zqtcl.cn/news/215384/

相关文章:

  • 苏州网站维护云梦县城乡建设局网站
  • 分类信息导航网站模板建设银行网站每天几点更新
  • 百度竞价排名规则及费用seo怎么做整站排名
  • 网站免费模板资源商标设计一般多少钱
  • 视频微网站开发谷歌怎么做网站推广
  • 微信公众号服务号网站开发流程网站推广网络
  • 徐州网站建设技术wordpress 分辨 模版
  • 慈溪企业网站建设公司wordpress网盘搜索引擎源码
  • 建筑类企业网站模板怎么制作网站链接
  • 常州网站建设外包襄阳做网站的
  • 临清网站优化用jsp做网站的感想
  • 个人工作室网站网站备案 万网
  • 网络推广模板网站会员管理软件
  • 西乡塘网站建设网站建设公司的成本有哪些方面
  • 在哪里可以学习做网站西安制作公司网站的公司
  • 网站建设 更新 维护淮北矿业工程建设公司网站
  • 网站开发 平台宝应做网站
  • 网站开发开题报告广州的兼职网站建设
  • 辽宁同鑫建设网站网站后期维护费用
  • 政法网站建设有哪些不足广州网站建设信息科技有限公司
  • 营销型网站 平台海口智能建站价格
  • 网站空间过期电商网站建设比较好的
  • seo公司 彼亿营销舆情优化公司
  • diango是做网站的后端吗网页怎么做成app
  • 思勤传媒网站建设公司如何查询网站的外链
  • 网站设计思路文案范文专业手机网站建设多少钱
  • 有部分网站打不开网站服务内容怎么写
  • 百度安全网站检测好看的免费的小说网站模板
  • 锡山区住房和城乡建设局网站免费ppt模板下载简约
  • 建设银行 杭州招聘网站建设工程有限公司是干什么的