logic

How to sort flat array into multidimensional tree

烈酒焚心 提交于 2019-12-21 17:40:15
问题 I have a table like id catagory suboff 1 software 0 2 programming 1 3 Testing 1 4 Designing 1 5 Hospital 0 6 Doctor 5 7 Nurses 5 9 Teaching 0 10 php programming 2 11 .net programming 2 How to write a code to get all these information in a multidimensional array based on the suboff as follows, -software --programming ---php programming --- .net programming --testing --designing -hospital --doctor --nurses -teaching 回答1: Assuming MySQL as your DB engine: // We'll need two arrays for this $temp

Converting string array to hashmap [duplicate]

守給你的承諾、 提交于 2019-12-21 17:16:44
问题 This question already has answers here : Converting string arrays into Map (5 answers) Closed 3 years ago . I have the following response T2269|175@@2a1d2d89aa96ddd6|45464047 By using the split("\\|") i have converted into string array object. The meaning for the each field is as follows: T2269 id 175@@2a1d2d89aa96ddd6 cid 45464047 refno No i have to convert it into HashMap object . Is their any solution for the above.. The above response is given for example. In real, the length of the

Why isn't this DirectoryInfo comparison working? [duplicate]

廉价感情. 提交于 2019-12-21 12:17:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to check whether 2 DirectoryInfo objects are pointing to the same directory? var dirUserSelected = new DirectoryInfo(Path.GetDirectoryName("SOME PATH")); var dirWorkingFolder = new DirectoryInfo(Path.GetDirectoryName("SAME PATH AS ABOVE")); if (dirUserSelected == dirWorkingFolder) { //this is skipped } if (dirUserSelected.Equals(dirWorkingFolder)) { //this is skipped } Whilst debugging, I can examine the

If Statement True Block Executed When Condition is False

折月煮酒 提交于 2019-12-21 07:55:55
问题 I optimized an extension method to compare two streams for equality (byte-for-byte) - knowing that this is a hot method I tried to optimize it as far as possible (the streams can reach into multi-megabyte lengths). I essentially came up with the following approach: [StructLayout(LayoutKind.Explicit)] struct Converter { [FieldOffset(0)] public Byte[] Byte; [FieldOffset(0)] public UInt64[] UInt64; } /// <summary> /// Compares two streams for byte-by-byte equality. /// </summary> /// <param name

Swapping column values in Oracle

梦想与她 提交于 2019-12-21 07:26:58
问题 I was solving one of the puzzles and came across swapping column values using DML queries: SELECT * FROM TEMP_TABLE; ID1, ID2 -------- 20, 15 20, 15 20, 15 Solution is mathematical calculation: UPDATE TEMP_TABLE SET ID1=ID1+ID2; UPDATE TEMP_TABLE SET ID2=ID1-ID2; UPDATE TEMP_TABLE SET ID1=ID1-ID2; Now, I am trying to figure out whether this can be applied to Strings or not, please suggest. SELECT * FROM TEMP_TABLE_NEW; ID1, ID2 -------- ABC, XYZ ABC, XYZ ABC, XYZ 回答1: There's no need to have

Algorithm to determine the “usual” cash payment amounts for a given price

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 05:12:11
问题 You walk into a store, select several products, then go to the counter to pay your bill. The total is some amount ( A ). You reach into your wallet, purse, or pocket and put down some cash ( P ), where P >= A , and the cashier gives you change. Given the set of coins and bills that are in circulation, what are the most likely values for P ? Some examples, assuming that the available bills are $5, $10, $20, $50 and $100, and the available coins are 5c, 10c and 25c: A = $151.24 P[1] = $160 (8x

reverse the position of integer digits?

こ雲淡風輕ζ 提交于 2019-12-21 01:42:47
问题 i have to reverse the position of integer like this input = 12345 output = 54321 i made this but it gives wrong output e.g 5432 #include <iostream> using namespace std; int main(){ int num,i=10; cin>>num; do{ cout<< (num%i)/ (i/10); i *=10; }while(num/i!=0); return 0; } 回答1: Your loop terminates too early. Change }while(num/i!=0); to }while((num*10)/i!=0); to get one more iteration, and your code will work. 回答2: Here is a solution int num = 12345; int new_num = 0; while(num > 0) { new_num =

reverse the position of integer digits?

老子叫甜甜 提交于 2019-12-21 01:41:28
问题 i have to reverse the position of integer like this input = 12345 output = 54321 i made this but it gives wrong output e.g 5432 #include <iostream> using namespace std; int main(){ int num,i=10; cin>>num; do{ cout<< (num%i)/ (i/10); i *=10; }while(num/i!=0); return 0; } 回答1: Your loop terminates too early. Change }while(num/i!=0); to }while((num*10)/i!=0); to get one more iteration, and your code will work. 回答2: Here is a solution int num = 12345; int new_num = 0; while(num > 0) { new_num =

How to prove excluded middle is irrefutable in Coq?

淺唱寂寞╮ 提交于 2019-12-20 10:44:57
问题 I was trying to prove the following simple theorem from an online course that excluded middle is irrefutable, but got stuck pretty much at step 1: Theorem excluded_middle_irrefutable: forall (P:Prop), ~~(P \/ ~ P). Proof. intros P. unfold not. intros H. Now I get: 1 subgoals P : Prop H : P \/ (P -> False) -> False ______________________________________(1/1) False If I apply H , then the goal would be P \/ ~P , which is excluded middle and can't be proven constructively. But other than apply ,

Find the biggest interval that has all its members in list in O(n) [duplicate]

随声附和 提交于 2019-12-20 08:25:01
问题 This question already has answers here : Finding contiguous ranges in arrays (8 answers) Longest Consecutive Sequence in an Unsorted Array [duplicate] (8 answers) Closed 6 years ago . I was asked this in an interview. Given a list of integers, How can we find the biggest interval that has all its members in the given list? E.g. given list 1,3,5,7,4,6,10 then answer would be [3, 7]. Because it has all the elements between 3 and 7. I tried to answer but I wasn't convincing. The approach I took