日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sql 算出下级销售总和_找出总和字符串

發布時間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sql 算出下级销售总和_找出总和字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 TT 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

T=3Str= "12345168213""123" + "45" = "168""45" + "168" = "213"It is a sum stringStr= "123581321" "1" + "2" = "3""2" + "3" = "5""3" + "5" = "8""5" + "8" = "13""8" + "13" = "21"It is a sum stringStr= "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(j+1,k) = str.substring(k+1,l)str.substring(j+1,k) + str.substring(k+1,l) = str.substring(l+1,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 lengthif (pos + str1_len + str2_len >= n)return false;//calculate the sumstring s = add(str.substr(pos, i), str.substr(pos + i, j));//if the next substring of pos+i+j is equals to the sumif (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 combinationsfor (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.aspx

    sql 算出下級銷售總和

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的sql 算出下级销售总和_找出总和字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。