Nish
BAN USER#include <iostream>
using namespace std;
string ReverseWordOrders(string s)
{
int index = s.length() - 1;
string temp,result;
for(int i=0; i<=index; i++)
{
if(s[i] != ' ')
{
temp = temp + s[i];
}
else
{
result = ' ' + temp + result;
temp.clear();
}
if(i == index)
{
result = temp + result;
}
}
return result;
}
int main()
{
string myString;
cout << "Enter any string:";
getline(cin,myString);
myString = ReverseWordOrders(myString);
cout<< "String after reversing word orders:" << myString << endl;
return 0;
}
namespace HighestOccurrencesOfCharacters
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter any string:");
string s = Console.ReadLine();
Dictionary<char, int> result = new Dictionary<char, int>();
result = HighestOccurrencesOfCharacters(s);
var max = result.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
int numberOfOccurrence = result[max];
Console.WriteLine("Highest Occuring Character is: {0}\n\nNumber of Occurrence: {1}", max, numberOfOccurrence);
Console.ReadLine();
}
protected static Dictionary<char, int> HighestOccurrencesOfCharacters(string s)
{
Dictionary<char, int> result = new Dictionary<char, int>();
int value;
foreach (char ch in s)
{
if (result.TryGetValue(ch, out value))
{
result[ch] = value + 1;
}
else
{
result.Add(ch, 1);
}
}
return result;
}
}
}
protected static string ReverseOrderingOfWords(string s)
{
string temp = string.Empty;
string reverse = string.Empty;
int counter = 0;
foreach (char ch in s)
{
counter++;
if (!char.IsWhiteSpace(ch))
{
temp = temp + ch;
}
else
{
reverse = " " + temp + reverse;
temp = string.Empty;
}
if (counter == s.Length)
{
reverse = temp + reverse;
}
}
return reverse;
}
- Nish October 12, 2013