Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Short
- {
- class Program
- {
- public static void Main(string[] args)
- {
- // A két egyező tömb
- int [] a = { -1, 2, 4, 3, -3, 7, -4, 5 };
- int [] b = { -1, 2, 4, 3, -3, 7, -4, 5 };
- // A tomb kiíratása
- foreach (var x in a) {
- Console.Write("{0,2} ",x);
- }
- Console.WriteLine();
- // B tömb rendezése
- Array.Sort(b);
- // Megkeressük az első nem negatív számot a rendezett (B) tömbben
- int k = 0;
- while(b[k] < 0) {
- k++;
- }
- // pozitív helyekre beillesztve a rendezett B tömb pozitív elemeit
- for (int i = 0; i < a.Length; i++) {
- if (a[i] >= 0) {
- a[i] = b[k];
- k++;
- }
- }
- // A tömb kiiratása (már rendezve a pozitív elemeket)
- foreach (var x in a) {
- Console.Write("{0,2} ",x);
- }
- Console.WriteLine();
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- }
- }
Add Comment
Please, Sign In to add comment