Introduction
A composite word is a concatenation of two-or-more other words, such that the minimum length of each constituent word is 3.
In this article the program which accepts a list of words and an integer or string as input and prints the count of composite words which can be constructed by concatenating integer and string or more other words which are also present in the input.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace ConsoleApplication3
- {
- class Program
- {
- static public void charsorting(char[] process, int length)
- {
- for (int a = 1; a < length; a++)
- {
- for (int b = 0; b < length - a; b++)
- {
- if (process[b] > process[b + 1])
- {
- char tempdata = process[b];
- process[b] = process[b + 1];
- process[b + 1] = tempdata;
- }
- }
- }
- }
- static public bool Permuation(char[] permute, int length)
- {
- for (int c = length - 1; c > 0; c--)
- {
- if (permute[c - 1] >= permute[c])
- continue;
- else
- {
- if (c <= length - 3)
- {
- char charcheck = permute[c - 1];
- int value = -1;
- for (int j = length - 1; j >= c; j--)
- {
- if (charcheck < permute[j])
- {
- value = j;
- break;
- }
- }
- if (value == -1)
- return false;
- char character = permute[c - 1];
- permute[c - 1] = permute[value];
- permute[value] = character;
- char[] process2 = new char[length - c];
- for (int d = 0; d < length - c; d++)
- process2[d] = permute[c + d];
- charsorting(process2, length - c);
- for (int e = 0; e < length - c; e++)
- permute[c + e] = process2[e];
- return true;
- }
- else
- {
- char[] dump = new char[3];
- dump[0] = permute[permute.Length - 3];
- dump[1] = permute[permute.Length - 2];
- dump[2] = permute[permute.Length - 1];
- int count = 3;
- for (int f = count - 1; f > 0; f--)
- {
- if (dump[f - 1] >= dump[f])
- continue;
- else
- {
- if (f <= count - 2)
- {
- if (dump[f + 1] > dump[f - 1])
- {
- char ch1 = dump[f + 1];
- dump[f + 1] = dump[f];
- dump[f] = dump[f - 1];
- dump[f - 1] = ch1;
- }
- else
- {
- char ch2 = dump[f - 1];
- dump[f - 1] = dump[f];
- dump[f] = dump[f + 1];
- dump[f + 1] = ch2;
- }
- }
- else
- {
- char ch3 = dump[f];
- dump[f] = dump[f - 1];
- dump[f - 1] = ch3;
- }
- permute[permute.Length - 3] = dump[0];
- permute[permute.Length - 2] = dump[1];
- permute[permute.Length - 1] = dump[2];
- return true;
- }
- }
- return false;
- }
- }
- }
- return false;
- }
- static void Main(string[] args)
- {
- string number;
- int counter = 0;
- string line;
- // Read the file and display it line by line.
- System.IO.StreamReader file =
- new System.IO.StreamReader("E:\\Mvc Test\\ConsoleApplication1\\ConsoleApplication1\\File\\test.txt");
- int count = 0;
- Console.WriteLine("Enter the number :");
- number = Console.ReadLine();
- if (number != null)
- {
- while ((line = file.ReadLine()) != null)
- {
- string s = line + number;
- char[] buffer = s.ToCharArray();
- while (true)
- {
- Console.WriteLine(buffer);
- count++;
- if (Permuation(buffer, buffer.Length) == false)
- break;
- }
- }
- Console.WriteLine("\nCount: " + count);
- Console.ReadLine();
- counter++;
- file.Close();
- Console.ReadLine();
- }
- else
- {
- Console.WriteLine("Enter atleast one value..!!!");
- Console.ReadLine();
- }
- }
- }
- }
- System.IO.StreamReader file =
- new System.IO.StreamReader("E:\\Mvc Test\\ConsoleApplication1\\ConsoleApplication1\\File\\test.txt");
Output:

Personal Blog.

Saroj Kumar SahuPosted Jun 22, 2015, 5:11 AM
Good job
Jaipal ReddyPosted Jun 22, 2015, 12:49 AM
Nice work.
Upendra Pratap ShahiPosted Jun 19, 2015, 7:45 AM
nice work Rajesh
Rajeesh MenothPosted Jun 15, 2015, 4:25 AM
Thank You all .. :)
Vineeth VijayPosted Jun 15, 2015, 2:43 AM
Good one rajeesh
Saritha K TPosted Jun 15, 2015, 2:32 AM
Nice Work
Pankaj Kumar ChoudharyPosted Jun 14, 2015, 3:53 AM
Nice Blog..........