Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01. Reverse Strings
- You will be given series of strings until you receive an "end" command. Write a program that reverses strings and prints each pair on separate line in format "{word} = {reversed word}".
- Examples
- Input Output
- helLo helLo = oLleh
- Softuni Softuni = inutfoS
- bottle bottle = elttob
- end
- Dog Dog = goD
- caT caT = Tac
- chAir chAir = riAhc
- end
- using System;
- using System.Collections.Generic;
- namespace TextProcessing_Lab
- {
- class Program
- {
- static void Main(string[] args)
- {
- var word = string.Empty;
- while ((word = Console.ReadLine()) != "end")
- {
- var reversedWord = "";
- //for (int i = word.Length - 1; i >= 0; i--) //Simple way.
- //{
- // reversedWord += word[i];
- //}
- var listChar = new List<char>(); //Other way.
- foreach (var itemChar in word)
- {
- listChar.Add(itemChar);
- }
- listChar.Reverse();
- foreach (var item in listChar)
- {
- reversedWord += item;
- }
- /*foreach (var item in word) //Genius way.
- {
- reversedWord += word[word.Length - word.IndexOf(item) - 1];
- }*/
- Console.WriteLine($"{word} = {reversedWord}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment