SHARE
TWEET

Untitled

a guest Dec 8th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ErrorActionPreference= 'silentlycontinue'
  2. if ($args.Count -eq 0)
  3. {
  4.     $file = Read-Host -Prompt "Adja meg a fájl nevét"
  5. }
  6. elseif ($args.Count -ne 1)
  7. {
  8.     Write-Host Túl sok argumentumot adott meg!
  9.     exit
  10. }
  11. else
  12. {
  13.     $file = $args[0]
  14. }
  15. $lines = Get-Content $file
  16. $linenum = 0
  17. $evenlinesevensum = 0
  18. $oddlinesevensum = 0
  19. $evenlinesoddsum = 0
  20. $oddlinesoddsum = 0
  21. foreach ($i in $lines)
  22. {
  23.     $linenum = $linenum + 1
  24.     $line = $i.split(" ")
  25.     if (($linenum % 2) -eq 0)
  26.     {
  27.        
  28.         foreach ($j in $line)
  29.         {
  30.             if (($j % 2) -eq 0)
  31.             {
  32.                 $evenlinesevensum = $evenlinesevensum + $j
  33.             }
  34.             else
  35.             {
  36.                 $evenlinesoddsum = $evenlinesoddsum + $j
  37.             }
  38.         }
  39.     }
  40.     else
  41.     {
  42.         foreach ($j in $line)
  43.         {
  44.             if (($j % 2) -eq 0)
  45.             {
  46.                 $oddlinesevensum = $oddlinesevensum + $j
  47.             }
  48.             else
  49.             {
  50.                 $oddlinesoddsum = $oddlinesoddsum + $j
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. Write-Host Páros sorok páros elemeinek összege: $evenlinesevensum
  57. Write-Host Páros sorok páratlan elemeinek összege: $evenlinesoddsum
  58. Write-Host Páratlan sorok páros elemeinek összege: $oddlinesevensum
  59. Write-Host Páratlan sorok páratlan elemeinek összege: $oddlinesoddsum
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top