nyac55 Posted October 16, 2013 Report Share Posted October 16, 2013 Witam. Mam do wykonania program ,który prosi użytkownika o podanie 2 łańcuchów tekstowych w języku C#. To udało mi się zrobić ,lecz teraz z tych wyrazów muszę stworzyć 1 wypadkowy z odwróconą kolejnością liter i tutaj zaczyna się problem ,bo nie wiem jak to poprawnie zrobić. Proszę o pomoc?Przykładowo:wyraz 1: alawyraz 2: makotawyraz wypadkowy od tyłu: alaatokam.Ktoś może mi pomóc w napisaniu tego??_+_+_+_+_Obecnie mam coś takiego:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { string a,b; Console.WriteLine("Zostaniesz poproszony o podanie 2 ciagów znaków"); a=Console.ReadLine(); b=Console.ReadLine(); Console.WriteLine(a); Console.WriteLine(a + b); Console.ReadKey(); } }} Link to comment Share on other sites More sharing options...
Ellusion Posted October 16, 2013 Report Share Posted October 16, 2013 Na twoim miejscu wrzuciłbym oba wyrazy w dwie osobne tablice i odczytał je w odwrotnej kolejności tj. od ostatniej komórki do pierwszej. Najprostszy sposób i chyba najszybszy. Link to comment Share on other sites More sharing options...
wies.niak Posted October 16, 2013 Report Share Posted October 16, 2013 string c = new string(a.Reverse().ToArray());To nie C, żeby bawić się we wrzucanie do tablic i pętle Powyższy kod używa Linq (metoda Reverse(), a więc .NET 3.5). Link to comment Share on other sites More sharing options...
nyac55 Posted October 17, 2013 Author Report Share Posted October 17, 2013 Wynik:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { string a,b; Console.WriteLine("Zostaniesz poproszony o podanie 2 ciagów znaków."); Console.WriteLine("Podaj 1 ciąg:"); a=Console.ReadLine(); Console.WriteLine("Podaj 2 ciąg:"); b=Console.ReadLine(); string c = new string(a.Reverse().ToArray()); string d = new string(b.Reverse().ToArray()); Console.WriteLine("Twoj wynik to:"); Console.WriteLine(c+d); Console.ReadKey(); } }}Program działa poprawnie. Dzięki za pomoc.____________________________Proszę nie zamykać jeszcze tematu ,bo będę potrzebował jeszcze pomocy. Link to comment Share on other sites More sharing options...
Sevard Posted October 17, 2013 Report Share Posted October 17, 2013 Problem rozwiązany, więc temat zamykam.W razie potrzeby otwarcia tematu, proszę o kontakt przez PW. Link to comment Share on other sites More sharing options...