I
I
IQI2020-12-08 18:27:05
C++ / C#
IQI, 2020-12-08 18:27:05

Replace each '+' character in a string with a '-' character if the '+' is preceded by an odd number?

The essence of the task in a string (String or StringBuilder) is to replace each '+' character in a string with a '-' character if there is an odd number before the '+'.
I'm trying to do it somehow through the last character (digit), if the number ends with an odd number, then it itself is not even

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace labor4
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string str = Console.ReadLine();
            string[] subs = sb.Split(' ', '+', '-', '*', '/');
            



            foreach (var sub in subs)
            {
                char n = sub.Last();

                

                if (n=='1'|n=='3'|n=='5'|n=='7'|n=='9')
                {
                    
                    
                }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-12-08
@IQI

1) Turn the text into a StringBuilder so that characters can be changed
2) Find the plus sign
3) Check what the number is in front of it
4) Change the plus if needed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question