In: Computer Science
I want to know how the application domain is formulated as a CSP(Constraint Satisfaction Problem)?
Thanks~
In: Computer Science
Java
Supermegastaurants have overtaken megastaurants as the latest trend in dining. A supermegastaurant is characterized by enormous menus, four categories of food, and a rule that you must choose exactly one item from each category. You have won a gift certificate of M dollars to use at a megastaurant. In order to maximize your dining value, you wish to choose an item from each category such that the price is as close to M as possible.
Input Format
Input begins with five integers, A, B, C, D, and M, subject to the following constraints:
1 <= A, B, C, D <=
2000
1 <= M <= 2,147,000,000
Next is a line with A positive integers, each less or equal to than 2,147,000,000. These integers are the prices of items in the first category.
Next is a line with B positive integers, each less or equal to than 2,147,000,000. These integers are the prices of items in the second category.
Next is a line with C positive integers, each less or equal to than 2,147,000,000. These integers are the prices of items in the third category.
Next is a line with D positive integers, each less or equal to than 2,147,000,000. These integers are the prices of items in the fourth category.
Output Format
You are to output the total cost of the meal with a price closest to M.
Note: This cost can be equal to M, greater than M, or less than M. In the case of a tie costs, choose the cheaper of the two costs.
Sample Input
3 2 1 2 50
15 10 49
11 17
10
13 23
Sample Output
50
Explanation
Here you can choose items that exactly equal M:
10 + 17 + 10 + 13 = 50
1) An argument of the correctness of your code:
a) State a loop invariant.
b) Argue that the loop invariant is true before the loop starts executing.
c) Argue that the loop invariant remains true after each iteration of the loop.
d) Argue for the correctness of your algorithm based on the loop invariant.
In: Computer Science
Modern CPU architectures allow for two modes of operation. Explain what the goal of having these two modes is/are, and explain how two-mode operation is used to achieve this goal(s).
In: Computer Science
Python program that simulates playing a game where a US penny (radius of 3/8 inches) is tossed into a board with a 1-inch by 1-inch square. The player wins only if the penny lands entirely within the square. Estimate the probability of winning by repeating the game 1,000 times. Record the estimate of the winning chance as a comment. Also, find the winning probability.
Please use comments to better explain :)
In: Computer Science
Write a Java program/method that takes a LinkedList and returns a new LinkedList with the integer values squared and reversed. Example: if the LinkedList has (9, 5,4,6), then the returned list will have (36, 16,25,81). What is the time-complexity of your code? You must use listIterator for full credit.
public LinkedList getReverseSquaredList (LinkedList list) { }
In: Computer Science
how to use python to read from stdin and print stderr in bash
In: Computer Science
Regarding the lecture on HIT Overview, how do you distinguish between Operation System software, Utility software and Application software?
In: Computer Science
The object is to make this client code work:
'''
>>> s = Stack()
>>> s.push('apple')
>>> s
Stack(['apple'])
>>> s.push('pear')
>>> s.push('kiwi')
>>> s
Stack(['apple', 'pear', 'kiwi'])
>>> top = s.pop()
>>> top
'kiwi'
>>> s
Stack(['apple', 'pear'])
>>> len(s)
2
>>> s.isEmpty()
False
>>> s.pop()
'pear'
>>> s.pop()
'apple'
>>> s.isEmpty()
True
>>> s = Stack(['apple', 'pear', 'kiwi'])
>>> s = Stack(['apple', 'pear', 'kiwi'])
>>> s[0]
'apple'
>>>
'''
use python3.7
>>> s = Stack()
>>> s.push('apple')
>>> s
Stack(['apple'])
>>> s.push('pear')
>>> s.push('kiwi')
>>> s
Stack(['apple', 'pear', 'kiwi'])
>>> top = s.pop()
>>> top
'kiwi'
>>> s
Stack(['apple', 'pear'])
>>> len(s)
2
>>> s.isEmpty()
False
>>> s.pop()
'pear'
>>> s.pop()
'apple'
>>> s.isEmpty()
True
>>> s = Stack(['apple', 'pear', 'kiwi'])
>>> s = Stack(['apple', 'pear', 'kiwi'])
>>> s[0]
'apple'
>>>
check that Stacks constructed without a list remain
distinct
if you receive an error on s2 then you probably need to use a
default argument of None in __init__
(see the Queue class developed in class for an example)
>>> s = Stack()
>>> s.push('apple')
>>> s
Stack(['apple'])
>>> s2 = Stack()
>>> s2.push('pear')
>>> s2 # if this fails - see the TEST file for
explanation
Stack(['pear'])
In: Computer Science
Use while loop for the num inputs
#include
#include
using namespace std;
int main()
{
long long int digit;
long long int num1, num2, num3, num4, num5;
int ave;
cout << "Enter a 10 digit number: ";
cin >> digit;
num5 = digit %100;
digit = digit / 100;
num4 = digit %100;
digit = digit / 100;
num3 = digit %100;
digit = digit / 100;
num2 = digit %100;
digit = digit / 100;
num1 = digit %100;
digit = digit / 100;
cout << num1 << endl;
cout << num2 << endl;
cout << num3 << endl;
cout << num4 << endl;
cout << num5 << endl;
ave = (double)(num1 + num2 + num3 + num4 + num5) /
5;
cout << "Avg: " << ave <<
endl;
switch(ave/10){
case 9:
cout <<
"Grade: A";
break;
case 8:
cout <<
"Grade: B";
break;
case 7:
cout <<
"Grade: C";
break;
case 6:
cout <<
"Grade: D";
break;
default:
cout <<
"Grade: F";
break;
}
return 0;
}
In: Computer Science
One common use of this class is to parse comma-separated integers from a string (e.g., "23,4,56").
stringstream ss("23,4,56"); char ch; int a, b, c; ss >> a >> ch >> b >> ch >> c; // a = 23, b = 4, c = 56
You have to complete the function vector parseInts(string str). str will be a string consisting of comma-separated integers, and you have to return a vector of int representing the integers.
Note If you want to know how to push elements in a vector, solve the first problem in the STL chapter.
Input Format
The first and only line consists of n integers separated by commas.
Output Format
Print the integers after parsing it.
P.S.: I/O will be automatically handled. You need to
complete the function only.
Sample Input
23,4,56
Sample Output
23 4 56
How do I input a string to then convert the string into a integer vector.
In: Computer Science
Python program to simulate breaking a unit-length pencil into two places. Repeat the experiment 100,000 times and determine the average size of the smallest, middle-size, and the largest pieces. Record the estimate of the average sizes in your program
Please use comments to better explain what is happening in the code
In: Computer Science
Read a text file into arrays and output - Java Program
------------------------------------------------------------------------------
I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards to the other people in the group. I would then like the java program to output as a string each array and its elements.
Example of "input.txt" that would be read
4
2 3 4
1 3 4
1 2 4
1 2 3
As you can see the top line says there are 4 people in this group and person #1 which is line #2 prefers to be in a group with persons 2, 3, and 4 respectively. So for Person #1 it would be an Array with 3 elements being 2, 3, and 4 in that order.
The java program in this case would read the .txt file. create 4 arrays based on line #1 saying there are 4 people and then it would output as a string the 4 arrays and their respective elements in order,
Example Output:
Person #1 prefers 2, then 3, then 4
Person #2 prefers 1, then 3, then 4
.
.
.
The java program should be able to work with text files that have different numbers of people, it should create # of arrays based on the number on line 1.
In: Computer Science
In java, Write a program that reads a data file containing final exam scores for a class and determines the number of passing scores (those greater than 60) and the number of failing scores (those less than 60). The average score as well as the range of scores should also be determined.
The program should request the name of the data file from the end user. The file may contain any number of scores. Using a loop, read and process each score until the end of file is encountered. Once all data has been processed, display the statistics.
The input file should consist of integer values between 1 and 100. We will assume that the data file contains only valid values. The data file can be created using jGrasp by using File | New | Plain Text. The file should be stored in the same folder as the .java file.
Hint: The smallest and largest values can be determined as the data is read if the variables are initialized to opposite values. For example, the variable holding the largest score is initialized to 0, and then reset as needed after each data item is read.
The Scanner class should be used to read the file. End user input/output may be accomplished using either a) Scanner & print methods, OR (b) JOptionPane methods. All end user input and output must use the same I/O technique.
The throws clause should be added to the main method header:
public static void main(String[] args) throws IOException
Example run 1:
Enter the file name to be read: scores1.dat
15 scores were read:
14 passing scores
1 failing scores
The score ranges from 50 to 100
The average is 79.80
Example run 2:
Enter the file name to be read: scores2.dat
20 scores were read:
17 passing scores
3 failing scores
The scores ranges from 52 to 99
In: Computer Science
In: Computer Science