Hirdetés
- One mobilszolgáltatások
- Honor Magic8 Pro - bevált recept kölcsönvett hozzávalókkal
- Nő az eSIM-ek iránti igény
- Google Pixel topik
- Telekom mobilszolgáltatások
- Samsung Galaxy S25 - végre van kicsi!
- Okosóra és okoskiegészítő topik
- Android szakmai topik
- Samsung Galaxy Watch8 - Classic - Ultra 2025
- Yettel topik
Új hozzászólás Aktív témák
-
Lacces
őstag
Nos, köszönöm, a helpet, igyekeztem megírni a stuki alapján a kódot.
Valami nem stimmel az algoritmussal, (hosszabb bemeneti sztringeknél vettem észre)
Mert ezt kellene kapnom:
5 1 2 + 4 * + 3 -
De helyeztte ez jön ki...
5 1 2 + 4 * 3 - +using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace LengyelForma
{
class LengyelForma
{
static void Main(string[] args)
{
String str = "5 + ((1 + 2) * 4) - 3";
String result=LengyelFormaKonvertalas(str);
Console.WriteLine(result.ToString());
Console.ReadLine();
}
static String LengyelFormaKonvertalas(String input)
{
Stack stack = new Stack();
String str = input.Replace(" ",string.Empty);
StringBuilder formula = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
char x=str[i];
if (x == '(')
{
stack.Push(x);
}
else if (IsOperandus(x))
{
formula.Append(x);
}
else if (IsOperator(x))
{
while (stack.Count > 0 && (char)stack.Peek() != '(' && Prior(x) >= Prior((char)stack.Peek()))
{
char y = (char)stack.Pop();
formula.Append(y);
}
while (stack.Count > 0 && (char)stack.Peek() != '(' && Prior(x) > Prior((char)stack.Peek()))
{
char y = (char)stack.Pop();
formula.Append(y);
}
stack.Push(x);
}
else
{
char y = (char)stack.Pop();
if (y != '(')
{
formula.Append(y);
}
}
}
while (stack.Count>0)
{
char c = (char)stack.Pop();
if(c!='(')
formula.Append(c);
}
return formula.ToString();
}
static bool IsOperator(char c)
{
return (c=='-'|| c=='+' || c=='*' || c=='/');
}
static bool IsOperandus(char c)
{
return (c>='0' && c<='9' || c=='.');
}
static int Prior(char c)
{
switch (c)
{
case '=':
return 1;
case '+':
return 2;
case '-':
return 2;
case '*':
return 3;
case '/':
return 3;
case '^':
return 4;
default:
throw new ArgumentException("Rossz paraméter");
}
}
}
}
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Intel Modular Server Chassis MFSYS25 adattároló --4x900GB HDD + 7x600GB HDD
- EMC 15-slot Disk Array Enclosure for DataDomain -15x3TB HDD- Adattároló - 2db van
- HPE UPS Extended Runtime Module R8000/3, R12000/3 compatible - kiegészitő modul -rackbe szerelhető
- Dell PowerEdge M1000E Blade Chassis (CDV10)-without blades - Több db
- Dell PowerEdge R820 Blade Server- csak ház + alaplap - 2 db
- BESZÁMÍTÁS! MSI B450M R5 5500 16GB DDR4 512GB SSD RX 6500 XT 8GB Rampage SHIVA ADATA 600W
- Keresek Xbox Series S / Series X / Playstation 5 konzolokat
- Dell XPS 13 9310 i7-1185G7 16GB 512GB 13" FHD+ 1 év garancia
- Xiaomi Redmi Note 14 Pro+ 5G 512GB,Újszerű,Dobozaval,12 hónap garanciával
- Bomba ár! Dynabook Portege X30-F - i7-8565U I 16GB I 256SSD I 13,3" FHD I Cam I W11 I Garancia!
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs


