Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to program in c language (structured data)

+7 votes
asked Jul 13, 2021 by paulo magalhaes (1,480 points)
John is working in a mine, trying to get as much of the diamonds as he can "<>". It must exclude all sand particles "." process and with each diamond removal, new diamonds may be formed. If it has as an input .<...<<..>>....>....>>>., three diamonds are formed. The first is taken from <..>, resulting in .<...<>....>....>>>. Then the second diamond is removed, leaving .<.........>....>>>. The third diamond is then removed, remaining at the end .....>>>., without the possibility of extracting a new diamond.

Input
An integer value N representing the number of test cases must be read. Each line below is a test case containing up to 1000 characters, including "<,>, ."

Exit
You must print the amount of diamonds possible to be extracted in each input case.

Input Example Output Example
two

<..><.<..>>

<<<..<......<<<<....>

3

1

1 Answer

0 votes
answered Jul 13, 2021 by Peter Minarik (84,720 points)
edited Jul 15, 2021 by Peter Minarik
This is actually a very easy one.

You really have to give it a try on your own first.

Start checking if from the input you receive an opening diamond (<), then listen for closing diamonds (>).

Keep a tab on how many opening - closing pairs there are and that's the answer.

As you can see, the logic is easy. Go ahead, try to do an implementation. It shouldn't take more than 20-30 lines of code.

When you have some code and you really cannot continue forward, share what you have that far. (I mean the minimum is that you have a main, have the input, iterate through the individual characters and check if they are opening/closing diamonds.)

Note: If you have never ever written a C program in your life, you should check out some tutorials  first (e.g. https://www.tutorialspoint.com/cprogramming/index.htm).

Good luck!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...