An input text consists of one or more words separated from each other by one or more spaces and terminated more spaces followed by a point. Input should be read from, and including, the first letter of the first word, up to and including the terminating point.
The output text is to be produced such that successive words are separated by a single space with the last word being terminated by a single point. Odd words are copied in reverse order while even words are kept as it is.
For example, the input string
: get busy living or get busy dying.
becomes
: get ysub living ro get ysub dying.

Ramesh MaruthiRank #937 · 2.2K reputationPosted Aug 24, 2015, 10:04 AM EDT
{
static void Main(string[] args)
{
string s = "get busy living or get busy dying";
Program p = new Program();
string result = p.oddreverse(s);
Console.WriteLine("Result is {0}", result);
Console.ReadLine();
}
public string oddreverse(string s)
{
string[] arrays = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var odds = arrays.Where((item, index) => index % 2 != 0);
var evens = arrays.Where((item, index) => index % 2 == 0);
foreach(string word in odds)
{
char[] arr = word.ToCharArray();
Array.Reverse(arr);
string rev = new string(arr);
arrays = arrays.Select(q => q.Replace(word, rev)).ToArray();
}
string reversedstrings = string.Join(" ", arrays);
return reversedstrings;
}
}
Sam HobbsRank #107 · 20.5K reputationPosted Aug 24, 2015, 11:12 AM EDT
Valarmathi33 reputationPosted Aug 24, 2015, 7:53 PM EDT
Valarmathi33 reputationPosted Aug 24, 2015, 7:57 PM EDT
For e.g.: power (a, b) will calculate value for ab and return.