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.

Code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static public void charsorting(char[] process, int length)
  12. {
  13. for (int a = 1; a < length; a++)
  14. {
  15. for (int b = 0; b < length - a; b++)
  16. {
  17. if (process[b] > process[b + 1])
  18. {
  19. char tempdata = process[b];
  20. process[b] = process[b + 1];
  21. process[b + 1] = tempdata;
  22. }
  23. }
  24. }
  25. }
  26. static public bool Permuation(char[] permute, int length)
  27. {
  28. for (int c = length - 1; c > 0; c--)
  29. {
  30. if (permute[c - 1] >= permute[c])
  31. continue;
  32. else
  33. {
  34. if (c <= length - 3)
  35. {
  36. char charcheck = permute[c - 1];
  37. int value = -1;
  38. for (int j = length - 1; j >= c; j--)
  39. {
  40. if (charcheck < permute[j])
  41. {
  42. value = j;
  43. break;
  44. }
  45. }
  46. if (value == -1)
  47. return false;
  48. char character = permute[c - 1];
  49. permute[c - 1] = permute[value];
  50. permute[value] = character;
  51. char[] process2 = new char[length - c];
  52. for (int d = 0; d < length - c; d++)
  53. process2[d] = permute[c + d];
  54. charsorting(process2, length - c);
  55. for (int e = 0; e < length - c; e++)
  56. permute[c + e] = process2[e];
  57. return true;
  58. }
  59. else
  60. {
  61. char[] dump = new char[3];
  62. dump[0] = permute[permute.Length - 3];
  63. dump[1] = permute[permute.Length - 2];
  64. dump[2] = permute[permute.Length - 1];
  65. int count = 3;
  66. for (int f = count - 1; f > 0; f--)
  67. {
  68. if (dump[f - 1] >= dump[f])
  69. continue;
  70. else
  71. {
  72. if (f <= count - 2)
  73. {
  74. if (dump[f + 1] > dump[f - 1])
  75. {
  76. char ch1 = dump[f + 1];
  77. dump[f + 1] = dump[f];
  78. dump[f] = dump[f - 1];
  79. dump[f - 1] = ch1;
  80. }
  81. else
  82. {
  83. char ch2 = dump[f - 1];
  84. dump[f - 1] = dump[f];
  85. dump[f] = dump[f + 1];
  86. dump[f + 1] = ch2;
  87. }
  88. }
  89. else
  90. {
  91. char ch3 = dump[f];
  92. dump[f] = dump[f - 1];
  93. dump[f - 1] = ch3;
  94. }
  95. permute[permute.Length - 3] = dump[0];
  96. permute[permute.Length - 2] = dump[1];
  97. permute[permute.Length - 1] = dump[2];
  98. return true;
  99. }
  100. }
  101. return false;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. static void Main(string[] args)
  108. {
  109. string number;
  110. int counter = 0;
  111. string line;
  112. // Read the file and display it line by line.
  113. System.IO.StreamReader file =
  114. new System.IO.StreamReader("E:\\Mvc Test\\ConsoleApplication1\\ConsoleApplication1\\File\\test.txt");
  115. int count = 0;
  116. Console.WriteLine("Enter the number :");
  117. number = Console.ReadLine();
  118. if (number != null)
  119. {
  120. while ((line = file.ReadLine()) != null)
  121. {
  122. string s = line + number;
  123. char[] buffer = s.ToCharArray();
  124. while (true)
  125. {
  126. Console.WriteLine(buffer);
  127. count++;
  128. if (Permuation(buffer, buffer.Length) == false)
  129. break;
  130. }
  131. }
  132. Console.WriteLine("\nCount: " + count);
  133. Console.ReadLine();
  134. counter++;
  135. file.Close();
  136. Console.ReadLine();
  137. }
  138. else
  139. {
  140. Console.WriteLine("Enter atleast one value..!!!");
  141. Console.ReadLine();
  142. }
  143. }
  144. }
  145. }
File Path:
  1. System.IO.StreamReader file =
  2. new System.IO.StreamReader("E:\\Mvc Test\\ConsoleApplication1\\ConsoleApplication1\\File\\test.txt");
Change your file path otherwise you got some error.right click the test.txt inside the file folder.then you get file path.

Output:

Output

Personal Blog.