Write a function cube_all_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the numbers in values (i.e., the numbers raised to the third power). This version of the function may not use recursion.
In: Computer Science
Write a complete Java program to create three types of counters as follows:
Please follow these notes:
In: Computer Science
Write a 'C' program to calculate the surface area of the cone and by using that, also calculate the volume of the cone and print the values as surface area of the cone and volume of the cone.
where as:
surface area of the cone = πr2 (r is the radius of the surface)
volume of the cone = (1/3)πr2h (h is the height of the cone)
In: Computer Science
void doSomething(int num)
Which of the following would be valid ways to invoke this
method?
答案选项组
System.out.println(doSomething(5));
doSomething("word".length());
doSomething(4);
doSomething(int);
doSomething(4.0);
doSomething(Math.random());
doSomething(7 + 5);
int answer = doSomething(5);
double result = doSometing(23);
doSomething((int)Math.PI);
In: Computer Science
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