how to concatenate the values

Posted by Murugavelmsc under C# on 2/28/2013 | Points: 10 | Views : 971 | Status : [Member] | Replies : 10
Hi Experts,

Input:

10, 12, 3, 23, 6, 7, 9, 1, 11, 8


output
1, 3, 6-7, 8-12, 23

Please help me

Thanks,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Jayakumars on: 2/28/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

what is ur logic?

Mark as Answer if its helpful to you

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

order the given number in ascending ....

Regards,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/28/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I cant figure out this logic


Thank you for posting at Dotnetfunda
[Administrator]

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Somu475 on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Murugavelmsc,

Please elaborate your logic.

If you want to arrange the given numbers in ascending order then what is this series 1, 3, 6-7, 8-12, 23 ...??





-Somu

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Somu,

sort the given as ascending as follows:

1, 3, 6, 7, 8, 9, 10, 11, 12, 23

then check the two numbers .....
1, no consective numbers, 3, no consectives number, 6,7,8,9,10,11,12 consective numbers so replace as 6-12, and 23....

I hope u are clear now....

Thanks,
Murugavel S




Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hai

int [] i = new int [10] {25,78,1,78,69,410,782,84,46,6} ;
Array.Sort(i);
foreach (int print in i)
{
Console.Write (print +"\n " );

}
Regards


Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi All

I got it....

Console.WriteLine("Enter input values seperated by comma");
string val = Console.ReadLine();

ArrayList inputval = new ArrayList();

// Split the input values and stored in arraylist
ArrayList spltval = new ArrayList(val.Split(','));
int i = 0;

// Convert the splitval to integer and stored in arraylist
for (i = 0; i < spltval.Count; i++)
inputval.Add(Convert.ToInt32(spltval[i]));

// Sort the arraylist
inputval.Sort();

Console.WriteLine("Input values after sorting");
Console.WriteLine("**************************");

for (i = 0; i < inputval.Count; i++)
Console.WriteLine(inputval[i]);

Console.WriteLine("Ouput values");
Console.WriteLine("************");

// Method call to Get the series result
GetResult(inputval, 0);

Console.ReadKey();
}

static private void GetResult(ArrayList arrval, int index)
{
// start value of the series
int startval = Convert.ToInt32(arrval[index]);

// end value of the series
int endval = Convert.ToInt32(arrval[arrval.Count - 1]);

int series = startval;
int i;

// Check the series
for (i = index; i < arrval.Count; i++)
{
int cmpval1 = int.Parse(arrval[i].ToString());
int cmpval2 = series++; //+i;

if (cmpval1 != cmpval2)
{
endval = int.Parse(arrval[i - 1].ToString());
break;
}
}

index = i;

// print result
Console.WriteLine(startval + "-" + endval);

// Recurssion - Call if the arraylist is completed or not
if (i < arrval.Count - 1)
GetResult(arrval, index);

return;
}

Thanks,
Murugavel S



Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mutturaj on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

I understood your logic like that only, but in original post you have mentioned 1, 3, 6-7, 8-12, 23 instead of 1, 3, 6-12, 23.

I think everyone got confused because of that. So plz post properly from next time.

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
yeah....

sorry for the inconvenience...


Thanks,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 2/28/2013 [Member] Silver | Points: 25

Up
0
Down
which type of variable used here...?

I will give solution..

Regards,
Singaravel M

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response