monish.gupta1
BAN USER@buried.shopno: consider 4 numbers as a=0, b=2, c=1 and d=3 from 4 arrays respectively (smallest one among non-seen ones from each array).
How come you can sort these four values because that changes the result in this case?
1.abs(a-b) + abs(b-c) + abs(c-d) + abs(d-a) = 2+1+2+3 = 8
2.How to use your funda (a >= b >= c >= d) here?
//assuming rand5() returns a number in range 0 to 4
int rand7(){//returns a number in range 0 to 6
sum = (rand5()+rand5()+rand5()+rand5()+rand5());//0 to 20
return sum/3;
@Ryan: Could you write some comments in the main function which would help to understand the algorithm.
Link of Haskell code you provided is fine. Due to C/C++ background, I am neither able to understand its code nor the algo given there due to its complex explanation.
Correct Ans: Undefined Behaviour
Explanation: Note that a function call f(a,b,c) is not a use of the comma operator and the order of evaluation for a, b, and c is unspecified.
Source: en.wikipedia.org/wiki/Sequence_point
@wavelet: Could you elaborate your algo?
- monish.gupta1 October 31, 2011<pre lang="" line="1" title="CodeMonkey50448" class="run-this">/*
Test Input:
I am a final year BE student.
9
Output:
I am a
final
year BE
student.
*/
import java.util.Scanner;
import java.util.Vector;
class Test{
String inpStr;
int aInt;
private Vector<String> aVecStr = new Vector<String>();
Test(int mm, String ss){
inpStr = ss;
aInt = mm;
}
public void convert(){
String[] words = inpStr.split(" ");
String str = new String("");
for(String tmp: words){
if(str.length() + tmp.length() > aInt){
aVecStr.add(str);
str = "";
}
str += tmp+" ";
}
if(str.length()>0)
aVecStr.add(str);
}
public void print(){
for(String s: aVecStr){
System.out.println(s);
}
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
Test t = new Test(9,"I am a final year BE student.");
t.convert();
t.print();
}
}</pre><pre title="CodeMonkey50448" input="yes">
</pre>
check this codepad.org/FHEj9jij
it runs well
.
On uncommenting the lines in main() : codepad.org/sUM5mkBS
it gives error.
How to do it correctly?
good one. Here is its implementation:
- monish.gupta1 November 06, 2011ideone.com/lUgZz