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
Karolina [17]
3 years ago
5

Write a C++ program that searches for anagrams in a dictionary. An anagram is a word obtained by scrambling the letters of some

string.
Computers and Technology
1 answer:
Semmy [17]3 years ago
8 0

Answer:

d, avt, car, feet, more, pitch, rome, tac, teef,

Anagrams of b in dictionary

Anagrams of cat in dictionary

avt, cat, tac,

Anagrams of room in dictionary

more, rome,

Anagrams of hello in dictionary

Anagrams of  in dictionary

Explanation:

// FindAnagrams.cpp : it is the starting point of application console.

//

#include <vector>

#include <hash_map>

#include <iostream>

#include <string>

#include <algorithm>

#include <map>

#include <set>

using namespace std;

using namespace stdext;

bool IsAnagrams(string& strA, string& strB)

{

   list<char> listA(strA.begin(), strA.end());

   list<char> listB(strB.begin(), strB.end());

   listA.sort();

   listB.sort();

   return listA == listB;

   // return equal(listA.begin(), listA.end(), listB.begin());

}

string SortChars(string str)

{

   list<char> l(str.begin(), str.end());

   l.sort();

   return string(l.begin(), l.end());

}

set<string> FindAnagrams(list<string>& dict, string findStr)

{

   map<string, set<string>> d;

   typedef pair<string, set<string>> MyPair;

   for(list<string>::const_iterator it = dict.begin(); it != dict.end(); ++it){

       string str(SortChars(*it));

       if(d.find(str) == d.end()){

           set<string> s;

           s.insert(*it);

           d.insert(MyPair(str, s));

       }

       else{

           d[str].insert(*it);

       }

   }

   string sortedStr(SortChars(findStr));

   return d[sortedStr];

}

int main(int argc, char* argv[])

{

   list<string> dict;

   dict.push_back("c");

   dict.push_back("car");

   dict.push_back("avt");

   dict.push_back("taac");

   dict.push_back("feet");

   dict.push_back("teef");

   dict.push_back("rom");

   dict.push_back("more");

   dict.push_back("pit");

   dict.sort();

   cout << "The dictionary: " << endl;

   copy(dict.begin(), dict.end(), ostream_iterator<string>(cout, ", "));

   cout << endl;

   list<string> testCases;

   testCases.push_back("d");

   testCases.push_back("car");

   testCases.push_back("rome");

   testCases.push_back("hell");

   testCases.push_back("");

   for(list<string>::iterator it = testCases.begin(); it != testCases.end(); ++it)

   {

       cout << endl << "Anagrams of " << *it << " in dictionary" << endl;

       set<string> output = FindAnagrams(dict, *it);

       copy(output.begin(), output.end(), ostream_iterator<string>(cout, ", "));

       cout << endl;

   }

   return 0;

}

You might be interested in
¿Toda sustancia de aspecto homogéneo es siempre una sustancia pura?
Gwar [14]

Answer:

No, las sustancias homogéneas pueden ser mezclas.

8 0
2 years ago
There will be 10 numbers stored contiguously in the computer at location x 7000 . Write a complete LC-3 program, starting at loc
Artist 52 [7]

Answer:

The LC-3 (Little Computer 3) is an ISA definition for a 16-bit computer. Its architecture includes physical memory mapped I/O via a keyboard and display; TRAPs to the operating system for handling service calls; conditional branches on N, Z, and P condition codes; a subroutine call/return mechanism; a minimal set of operation instructions (ADD, AND, and NOT); and various addressing modes for loads and stores (direct, indirect, Base+offset, PC-relative, and an immediate mode for loading effective addresses). Programs written in LC-3 assembler execute out of a 65536 word memory space. All references to memory, from loading instructions to loading and storing register values, pass through the get Mem Adr() function. The hardware/software function of Project 5 is to translate virtual addresses to physical addresses in a restricted memory space. The following is the default, pass-through, MMU code for all memory references by the LC-3 simulator.

unsigned short int get Mem Adr(int va, int rwFlg)

{

unsigned short int pa;

// Warning: Use of system calls that can cause context switches may result in address translation failure

// You should only need to use gittid() once which has already been called for you below. No other syscalls

// are necessary.

TCB* tcb = get TCB();

int task RPT = tcb [gettid()].RPT;

pa = va;

// turn off virtual addressing for system RAM

if (va < 0x3000) return &memory[va];

return &memory[pa];

} // end get MemAdr

Simple OS, Tasks, and the LC-3 Simulator

We introduce into our simple-os a new task that is an lc3 Task. An lc3 Task is a running LC-3 simulator that executes an LC-3 program loaded into the LC-3 memory. The memory for the LC-3 simulator, however, is a single global array. This single global array for memory means that alllc3 Tasks created by the shell use the same memory for their programs. As all LC-3 programs start at address 0x3000 in LC-3, each task overwrites another tasks LC-3 program when the scheduler swaps task. The LC-3 simulator (lc3 Task) invokes the SWAP command every several LC-3 instruction cycles. This swap invocation means the scheduler is going to be swapping LC-3 tasks before the tasks actually complete execution so over writing another LC-3 task's memory in the LC-3 simulator is not a good thing.

You are going to implement virtual memory for the LC-3 simulator so up to 32 LC-3 tasks can be active in the LC-3 simulator memory without corrupting each others data. To implement the virtual memory, we have routed all accesses to LC-3 memory through a get Mem Adr function that is the MMU for the LC-3 simulator. In essence, we now have a single LC-3 simulator with a single unified global memory array yet we provide multi-tasking in the simulator for up to 32 LC-3 programs running in their own private address space using virtual memory.

We are implementing a two level page table for the virtual memory in this programming task. A two level table relies on referring to two page tables both indexed by separate page numbers to complete an address translation from a virtual to a physical address. The first table is referred to as the root page table or RPT for short. The root page table is a fixed static table that always resides in memory. There is exactly one RPT per LC-3 task. Always.

The memory layout for the LC=3 simulator including the system (kernel) area that is always resident and non-paged (i.e., no virtual address translation).

The two figures try to illustrate the situation. The lower figure below demonstrates the use of the two level page table. The RPT resident in non-virtual memory is first referenced to get the address of the second level user page table or (UPT) for short. The right figure in purple and green illustrates the memory layout more precisely. Anything below the address 0x3000 is considered non-virtual. The address space is not paged. The memory in the region 0x2400 through 0x3000 is reserved for the RPTs for up to thirty-two LC-3 tasks. These tables are again always present in memory and are not paged. Accessing any RPT does not require any type of address translation.

The addresses that reside above 0x3000 require an address translation. The memory area is in the virtual address space of the program. This virtual address space means that a UPT belonging to any given task is accessed using a virtual address. You must use the RPT in the system memory to keep track of the correct physical address for the UPT location. Once you have the physical address of the UPT you can complete the address translation by finding the data frame and combining it with the page offset to arrive at your final absolute physical address.

A Two-level page table for virtual memory management.

x7000 123F x7000 0042

x7001 6534 x7001 6534

x7002 300F x7002 300F

x7003 4005 after the program is run, memory x7003 4005

x7004 3F19

7 0
3 years ago
Read 2 more answers
Write a method transpose, that takes as argument a 2D array of integers, myTable, and returns the transpose of myTable. The tran
Gelneren [198K]

Answer:

The program to this question can be given as:

Program:

import java.util.*; //import package

public class Main //defining class

{

public static int[][] transpose(int[][] a1) //defining function transpose

{

int i,j; //define variables

int[][] transpose = new int[a1[0].length][a1.length]; //define variable transpose.

//loop for transpose matrix.

for(i = 0; i < a1.length; i++)  

{

for(j = 0; j < a1[i].length; j++)

{

transpose [j][i] = a1[i][j]; //hold value in transpose variable

}

}

return transpose ; //return transpose matrix.  

}

public static void main(String[] args) //main method.

{

int row,col,i,j; //defining variable.

Scanner obj = new Scanner(System.in); //creating Scanner class Object

System.out.print("Enter number of rows: ");//message

row = obj.nextInt(); //input rows form user.

System.out.print("Enter number of columns: ");//message

col = obj.nextInt(); //input columns form user.

int[][] a1 = new int[row][col]; //defining array.

System.out.println("Enter matrix"); //message

// loop for input array elements from user

for(i=0; i<a1.length;i++)  

{

for(j=0; j<a1[i].length;j++)  

{

a1[i][j]=obj.nextInt(); //input in array variable.

}

}

System.out.println("Matrix you insert :"); //message

// loop for display array.

for(i=0; i<a1.length;i++)  

{

for(j=0; j<a1[i].length;j++)  

{

System.out.print(a1[i][j]+" "); //print matrix

}

System.out.print("\n");

}

int[][] result = transpose(a1); //define result array variable that holds function value.

System.out.println("Transposed matrix is :");

//use loop for print Transpose matrix.

for(i = 0;i < result.length;i++)

{

for (j = 0; j < result[i].length;j++)

{

System.out.print(result[i][j] + " "); //print matrix

}

System.out.print("\n");

}

}

}

Output:

Enter number of rows: 2

Enter number of columns: 3

Enter matrix

2

3

4

9

8

7

Matrix you insert :

2 3 4  

9 8 7  

Transposed matrix is :

2 9  

3 8  

4 7  

Explanation:

The description of the above program can be given as:

  • In the above program firstly import a package, then declare a class that is "Main" inside a class defining a transpose() function this function returns a matrix in transpose form.
  • In the main class, we define a variable and matrix that is "row, col, i, j and a1[][]".  Then we Creating a scanner class object, which is used by row, col and a1[][] variables for user input.  
  • The row and col variables are used to declare matrix size and i, j variable is used in the loop for insert and display matrix.  
  • a1[][] matrix is used for input matrix elements and passes into transpose() function as an argument that returns a value that is held in the result variable. This is used as a loop for the print transpose matrix.

5 0
3 years ago
Which two features could be added to a game using an "if () then" block?
xxTIMURxx [149]

The two features that could be added to a game using an "if () then" block are c. if the player touches a wall, it turns around and moves back 5 and d.

<h3>What does the If Then block mean?</h3>

The If-Then block is understood to be the output certainly considered one among given values, this is because of the fee of a Boolean enter.

Note that the entry fee could be very essential and as such, The functions will be introduced to a sport the use of an "if () then " block are: Using nested If-Then blocks. • Checks the particular Bid amount for the instrument.

Learn greater approximately game from :

brainly.com/question/1786465

#SPJ1

3 0
2 years ago
Addition and subtraction are considered to be ____ operations performed by a computer.
Natali5045456 [20]

Answer:

Mathematical operations

4 0
3 years ago
Other questions:
  • Carolyn owns a small business that designs air conditioning units for large buildings. A construction company that's building an
    13·1 answer
  • When did internet came to existence?
    12·1 answer
  • LargeCo is planning a new promotion in Alabama (AL) and wants to know about the largest purchases made by customers in that stat
    7·1 answer
  • Henry must choose which type of smart speaker to use in his home. He asked you to help him decide which one will best suit his n
    11·1 answer
  • Alright, don't judge me, this is a question that involves my Childhood game PvZ GW 2. So I noticed mods and stuff that get uploa
    12·2 answers
  • A computer with a frequency 2 GHZ and its average cycle per instruction is 2. what is the MIPS of the computer?
    6·1 answer
  • ____________________________ and _________________________ are 2 negative impacts of the internet on businesses.
    8·1 answer
  • A radio and communications security repairer is responsible for both radio and satellite communication systems.
    6·2 answers
  • How would you write this using Java: Use a TextField's setText method to set value 0 or 1 as a string?
    5·1 answer
  • Difference between sorting and filtering​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!