1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lawyer [7]
3 years ago
14

Write a program that inputs a line of text and uses a stack object to print the line reversed.

Computers and Technology
1 answer:
Lina20 [59]3 years ago
8 0

Answer:

#include <bits/stdc++.h>

using namespace std;

int main() {

   string ms;

   getline(cin,ms);

   stack<char>st;

   for(int i=0;i<ms.length();i++)//Inserting every element in the stack..

   {

       st.push(ms[i]);

   }

   while(!st.empty()) //doing operation until the stack is not empty..

   {

       char a=st.top();//accessing the top element of the stack...

       st.pop();//removing the head.

       cout<<a;//printing the character..

   }

return 0;

}

Input:-

murder

Ouput:-

redrum

Explanation:

An  easy way to reverse anything is to use stack.Since stack is LIFO type data structure so the last item in will be the first one to get out hence it reverses the elements.So inserting every element of the string into the stack of characters and then printing the every element of the stack from top to bottom.

You might be interested in
The _____ unit is the preferred style unit for web page text because it makes it easy to develop pages in which different page e
cluponka [151]
Em The answer that you are looking for is (em)
6 0
3 years ago
Read 2 more answers
What does a computer monitor look like when struck really hard?
sveticcg [70]

Answer:

physical damage could include broken glass or ink splotches on the display, distorted images, or discoloration

5 0
2 years ago
If you have downloaded this book's source code from the companion Web site, you will find a file named text.txt in the Chapter 1
Lubov Fominskaja [6]

Answer:

Explanation:

The following python code loops through each line within a file called text.txt and counts all the words, then it divides this count by the number of sentences in the text file. Finally, output the average number of words per sentence.

f = open("text.txt", "r")

all_words = 0

sentences = 0

for x in f:

   list = x.split(' ')

   all_words += len(list)

   sentences += 1

average = all_words / sentences

print("There are an average of " + str(average.__round__()) + " words in each sentence.")

6 0
3 years ago
You notice that it’s very easy to confuse medications at the community health center where you’re working. They are lined up on
Bezzdna [24]

Answer:

The answer is design systems to prevent errors.

Explanation:

This system helps to prevent medication errors with resultant patient harm and cost. The best would be if the community health center could afford systems that use information technology  such as computerized physician order entry, automated dispensing, barcode medication administration, among other technological solutions.

8 0
4 years ago
What is File Allocation Table
vichka [17]
It's how you format your hard drive
4 0
3 years ago
Read 2 more answers
Other questions:
  • Algorithm for converting decimal into binary.
    7·1 answer
  • Which of the following are characteristics of a good webmail message select all that apply
    14·1 answer
  • When listing columns in the select list, what should you use to separate the columns?
    6·1 answer
  • The indent buttons on the home tab allow you to increase or decrease paragraph indenting in increments of ____ inches.
    5·1 answer
  • What is a multipurpose network device?
    10·1 answer
  • Assume user_name equals "Tom" and user_age equals 22. What is printed on the console when the following statement is executed? c
    14·1 answer
  • We made a distinction between the forwarding function and the routing function performed in the network layer. What are the key
    6·1 answer
  • Which one of the statements best characterizes the current state of e-commerce?
    15·1 answer
  • Function of pons for class 7​
    15·1 answer
  • Henry wants to create a presentation for his clients. He wants to upload the presentation file directly to the Internet. Which p
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!