Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
කිතුල් තලප
Manoj Suranga Bandara
Updated:
Yesterday at 7:04 PM
Ad icon
ව්යාපාර, Tuition පන්ති සහ Personal Portfolios සඳහා Web Setup එකක් රු. 9,099/- කට (වාර්ෂික renewal ර
thathsilura
Updated:
Thursday at 6:17 PM
AWS Certified Solutions Architect-Associate + AWS Certified Cloud Practitioner
Sanjeewani95
Updated:
Aug 19, 2026
🚀 එක පැකේජ් එකයි - මාසෙටම Unlimited Internet! 🌐
sayuru bandara
Updated:
Aug 18, 2026
🎬 CapCut Pro 1 Month Access! LKR 600
sayuru bandara
Updated:
Aug 18, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
C# programming help
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="EKGuest" data-source="post: 28430274" data-attributes="member: 582168"><p>I had already coded the solution at the time I made my previous post asking for the constraints so that I could modify my code to suit the constraints. Anyway here is the solution that works for both capital and simple letters and supports multiple numbers within the sentence.</p><p></p><p>[CODE=csharp]using System;</p><p>using System.Linq;</p><p></p><p>public class Program</p><p>{</p><p> const int NO_OF_SENTENCES = 5;</p><p></p><p> static void Main(string[] args)</p><p> {</p><p> string[] sentences = ReadSentences();</p><p> string[] encodedSentences = EncodeSentences(sentences);</p><p></p><p> WriteEncodedSentences(sentences, encodedSentences);</p><p></p><p> Console.ReadLine();</p><p> }</p><p></p><p> static string[] EncodeSentences(string[] sentences)</p><p> {</p><p> string[] encodedSentences = new string[sentences.Length];</p><p></p><p> for (int i = 0; i < sentences.Length; i++)</p><p> encodedSentences[i] = EncodeSentence(sentences[i]);</p><p></p><p> return encodedSentences;</p><p> }</p><p></p><p> static string EncodeSentence(string sentence)</p><p> {</p><p> string encoded = "";</p><p> string number = "";</p><p></p><p> for (int i = 0; i < sentence.Length; i++)</p><p> {</p><p> if (Char.IsDigit(sentence[i]))</p><p> number = sentence[i] + number;</p><p> else</p><p> {</p><p> if (number != "")</p><p> {</p><p> encoded += int.Parse(number) * 2;</p><p> number = "";</p><p> }</p><p> encoded += GetEncodedLetter(sentence[i]);</p><p> }</p><p> }</p><p></p><p> return encoded;</p><p> }</p><p></p><p> static string GetEncodedLetter(char c)</p><p> {</p><p> string vowels = "AEIOU" + "AEIOU";</p><p> string consonants = "BCDFGHJKLMNPQRSTVWXYZ" + "BCDFGHJKLMNPQRSTVWXYZ";</p><p></p><p> if (Char.IsLower(c))</p><p> {</p><p> vowels = vowels.ToLower();</p><p> consonants = consonants.ToLower();</p><p> }</p><p></p><p> if (vowels.Contains(c))</p><p> return "" + vowels[vowels.LastIndexOf(c) - 2];</p><p> else if (consonants.Contains(c))</p><p> return "" + consonants[consonants.IndexOf(c) + 3];</p><p> else if (".!?".Contains(c))</p><p> return "#";</p><p> else if (Char.IsDigit(c))</p><p> return "" + c;</p><p> else if (c == ' ')</p><p> return " ";</p><p> else // Must be some other punctuation mark</p><p> return "";</p><p> }</p><p></p><p> static string[] ReadSentences()</p><p> {</p><p> string[] sentences = new string[NO_OF_SENTENCES];</p><p></p><p> for (int i = 0; i < sentences.Length; i++)</p><p> {</p><p> Console.Write("\nInput sentence No. {0}: ", i + 1);</p><p> sentences[i] = Console.ReadLine();</p><p> }</p><p></p><p> return sentences;</p><p> }</p><p></p><p> static void WriteEncodedSentences(string[] sentences, string[] encodedSentences)</p><p> {</p><p> Console.WriteLine("\n");</p><p></p><p> for (int i = 0; i < sentences.Length; i++)</p><p> {</p><p> Console.WriteLine("Sentence: {0}", sentences[i]);</p><p> Console.WriteLine("Encoded Sentence: {0}\n", encodedSentences[i]);</p><p> }</p><p> }</p><p>}[/CODE]</p><p></p><p><img src="https://i.ibb.co/xChXB76/1.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p></blockquote><p></p>
[QUOTE="EKGuest, post: 28430274, member: 582168"] I had already coded the solution at the time I made my previous post asking for the constraints so that I could modify my code to suit the constraints. Anyway here is the solution that works for both capital and simple letters and supports multiple numbers within the sentence. [CODE=csharp]using System; using System.Linq; public class Program { const int NO_OF_SENTENCES = 5; static void Main(string[] args) { string[] sentences = ReadSentences(); string[] encodedSentences = EncodeSentences(sentences); WriteEncodedSentences(sentences, encodedSentences); Console.ReadLine(); } static string[] EncodeSentences(string[] sentences) { string[] encodedSentences = new string[sentences.Length]; for (int i = 0; i < sentences.Length; i++) encodedSentences[i] = EncodeSentence(sentences[i]); return encodedSentences; } static string EncodeSentence(string sentence) { string encoded = ""; string number = ""; for (int i = 0; i < sentence.Length; i++) { if (Char.IsDigit(sentence[i])) number = sentence[i] + number; else { if (number != "") { encoded += int.Parse(number) * 2; number = ""; } encoded += GetEncodedLetter(sentence[i]); } } return encoded; } static string GetEncodedLetter(char c) { string vowels = "AEIOU" + "AEIOU"; string consonants = "BCDFGHJKLMNPQRSTVWXYZ" + "BCDFGHJKLMNPQRSTVWXYZ"; if (Char.IsLower(c)) { vowels = vowels.ToLower(); consonants = consonants.ToLower(); } if (vowels.Contains(c)) return "" + vowels[vowels.LastIndexOf(c) - 2]; else if (consonants.Contains(c)) return "" + consonants[consonants.IndexOf(c) + 3]; else if (".!?".Contains(c)) return "#"; else if (Char.IsDigit(c)) return "" + c; else if (c == ' ') return " "; else // Must be some other punctuation mark return ""; } static string[] ReadSentences() { string[] sentences = new string[NO_OF_SENTENCES]; for (int i = 0; i < sentences.Length; i++) { Console.Write("\nInput sentence No. {0}: ", i + 1); sentences[i] = Console.ReadLine(); } return sentences; } static void WriteEncodedSentences(string[] sentences, string[] encodedSentences) { Console.WriteLine("\n"); for (int i = 0; i < sentences.Length; i++) { Console.WriteLine("Sentence: {0}", sentences[i]); Console.WriteLine("Encoded Sentence: {0}\n", encodedSentences[i]); } } }[/CODE] [IMG]https://i.ibb.co/xChXB76/1.png[/IMG] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom