Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How do I get maximum key values in a Map and let's say save it to a List?
For example, is there is a Map:
John, 30
Alexander, 10
Ivan, 20
Steven, 30
The result must be a List: John, Steven
Without additional List...
Double max = 0d;
for (String key : wagesList.keySet()) {
if (wagesList.get(key) > max) {
max = wagesList.get(key);
}
}
for (String key : wagesList.keySet()) {
if (wagesList.get(key).equals(max)) {
System.out.println(key);
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
In Python I can do this:
a, b = map(int, input().split(" "))
... to get exactly 2 integers from user input.
How can I achive the exact same result in Rust (get 2 integers as a named tuple) without any extern crates?
For the sheer fun of it, I translated your code as literally as possible to Rust:
// replace with some read from stdin
let input = "1 2";
let (a, b) = if let &[a, b] = &input.split(' ').map(|c| c.parse::<u32>().unwrap()).collect::<Vec<_>>()[..] {
(a, b)
} else {
panic!("ValueError: too many/few values to unpack (expected 2)");
};
println!("a = {}, b = {}", a, b);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How to truncate f64 to 2 decimal places?
From
let before = 17.69108280254777;
To
let after = 17.69;
You can't actually get rounding without rounding, but i think a workaround like this can get the job done
fn main() {
let before = 17.69108280254777;
let after = f64::trunc(before * 100.0) / 100.0; // or f32::trunc
}
Outputs:
17.69
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there any way to use variable itself inside without it's name?
For example, I have a string like this:
someStuffVariableName = "abcdefghijklmnop..."
If I want to manipulate it, I need to write every time name of this var but it's so long:
someStuffVariableName = someStuffVariableName[0:-1]
But,anyway,can I do like this:
someStuffVariableName = self[0:-1] or someStuffVariableName = this.value[0:-1]?
There is not.
Your best options are:
Use a more concise variable name (but don't give up readability!)
Just deal with the length
Note that in some cases, the answer is actually yes. For instance, you can often write x += y instead of x = x + y, and x /= y instead of x = x / y.
But this is for assignment operators only.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a data list.
db = [("Ada","works", "IBM")
,("Alice","director", "Ada")
,("Tom","works", "IBM")
,("Tommy","director", "Tom")
,("IBM","isat", "CA")
,("CA","in", "USA")
]
ask db = map (\(x,y,z) -> (z == "IBM")) db
How to calculate the complexity of O(n)?
If I want to get the result by the length of list 2,5,10.O(n) is same like 2,5,10?And If I do
trans2 db = concat (map ((x,y,z) -> concat (map((x',y',z') -> if (z==x') then [] else [(x,y ++ "." ++ y',z')] else []) db)) db )
How can I calculate the O(n)? The runtime of program? The timming complexity
The question is unclear and I expect it will soon be closed. Briefly.
O(n) is a complexity. If you know O(n) and you wanted complexity then you're done.
The length of the list (2, 5, 10, what have you) is not a factor in the complexity in this case since the length is what the n is representing.
There is no code that will calculate the complexity of the algorithm automatically. It is a manual analysis.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In Haskell, how can I create a type to represent a list of length 9 which each elements are an Int between 0 and 9?
You could use smart constructors:
module Sudoku(SudokuSquare, sudokuSquare) where
import Data.Traversable(traverse)
data SudokuSquare = SSquare Int
sudokuSquare :: Int -> Maybe SudokuSquare
sudokuSquare i = if i >= 0 && i <= 9 then Just (SSquare i) else Nothing
buildRow :: [Int] -> Maybe [SudokuSquare]
buildRow = traverse sudokuSquare