numbers

Python - Check if the last characters in a string are numbers

 ̄綄美尐妖づ 提交于 2019-12-02 23:27:24
Basically I want to know how I would do this. Here's an example string: string = "hello123" I would like to know how I would check if the string ends in a number, then print the number the string ends in. I know for this certain string you could use regex to determine if it ends with a number then use string[:] to select "123". BUT if I am looping through a file with strings like this: hello123 hello12324 hello12435436346 ...Then I will be unable to select the number using string[:] due to differentiation in the number lengths. I hope I explained what I need clearly enough for you guys to help

Keep track of the lowest numbers in an array

纵饮孤独 提交于 2019-12-02 23:26:00
问题 I am trying to keep track of the the scores of the lowest numbers and if I find the lowest scores of those players I don't want them to play again in the next round. I have gotten to the point of storing those low player value into the array but I only want them to be stored ONCE. for(int i =0; i < player.length; i++){ for(int j =1; j < player.length; j++){ if(player[j] < player[i]){ min[i] =j; System.out.println(min[i]+" "+round+" "+playerList.get(j)); } } } 回答1: Do 2 separate loops instead.

How to Calculate (a/b) %c where a,b and c are very large numbers [closed]

廉价感情. 提交于 2019-12-02 23:00:53
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have a function f(x)=(1^1)*(2^2)*(3^3)*.....(x^x) i have to calculate (f(x)/(f(x-r)*f(r)))modulo c i can calculate f(x) and (f(x-r)*f(r)). assume f(x) is a and f(x-r)*f(r) is b. c is some number that is very larger. `` so i how can calculate (a/b)%c 回答1: your f(x) is just ᴨ (PI cumulative multiplication)

2. Add two numbers

匿名 (未验证) 提交于 2019-12-02 22:56:40
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807. 题意 以各位数倒序排列链表的形式给定两个整数,要求计算出两者之和,并同样以各位数倒序链表的形式返回结果。 ˼· 从两链表的个位数开始,依次计算各位数之和并判断记录进位。最后注意对最高位的进位进行处理。(注意先转换为两个整数再相加的方法会存在测试整数值超过上限的问题) 代码实现 - Java /** * Definition for singly-linked list. *

LeetCode 2 : Add Two Numbers

匿名 (未验证) 提交于 2019-12-02 22:56:40
题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input : ( 2 -> 4 -> 3 ) + ( 5 -> 6 -> 4 ) Output:7-> 0 -> 8 Explanation:342 + 465 = 807 思路: example 1: 2->4->3 5->6->4 (2+5+0)->(4+6+0)->(3+4+1) 第三个数代表进位 7->0->8 example 2: 1 9->9 (1+9+0)->(0+9+1)->(0+0+1) 0->0->1 代码: /** * Definition for singly-linked list. * struct

第四章-操作列表

匿名 (未验证) 提交于 2019-12-02 22:51:30
4-1 比萨 : 想出至少是三种你喜欢的比萨,将其名称存储在一个列表中,再使用for循环将每种比萨的名称都打印出来。 1 pizzas=['a','b','c'] 2 for pizz in pizzas: 3 print(pizz) 4 for pizza in pizzas: 5 print("I like "+pizza+" pizza.") 6 print('I really like pizza.') 输出: 1 a 2 b 3 c 4 I like a pizza. 5 I like b pizza. 6 I like c pizza. 7 I really like pizza. 4-2 动物 :想出至少三种有共同特征的动物,将这些动物的名称存储在一个列表中,再使用for 循环将每种动物的名称都打印出来。 1 animals=['cat','dog','pig'] 2 for anima in animals: 3 print(anima) 4 for animal in animals: 5 print("A "+animal+" would make a great pet.") 6 print("Any of these animals would make a great pet.") 输出: 1 cat 2 dog 3 pig 4 A cat would

Checking if string is numeric in dart

浪尽此生 提交于 2019-12-02 22:35:38
I need to find out if a string is numeric in dart. It needs to return true on any valid number type in dart. So far, my solution is bool isNumeric(String str) { try{ var value = double.parse(str); } on FormatException { return false; } finally { return true; } } Is there a native way to do this? If not, is there a better way to do it? This can be simpliefied a bit void main(args) { print(isNumeric(null)); print(isNumeric('')); print(isNumeric('x')); print(isNumeric('123x')); print(isNumeric('123')); print(isNumeric('+123')); print(isNumeric('123.456')); print(isNumeric('1,234.567')); print

Algorithm for digit summing?

我是研究僧i 提交于 2019-12-02 22:16:29
I'm searching for an algorithm for Digit summing. Let me outline the basic principle: Say you have a number: 18268 . 1 + 8 + 2 + 6 + 8 = 25 2 + 5 = 7 And 7 is our final number. It's basically adding each number of the whole number until we get down to a single (also known as a 'core') digit. It's often used by numerologists. I'm searching for an algorithm (doesn't have to be language in-specific) for this. I have searched Google for the last hour with terms such as digit sum algorithm and whatnot but got no suitable results. Because 10-1=9, a little number theory will tell you that the final

1s and 2s complement of a negative number

吃可爱长大的小学妹 提交于 2019-12-02 21:49:47
问题 All answers I seem to find on how to find the 1s (flip the bits of the positive) and the 2s (flip the bits of the positive binary and add 1) complement doesn't seem to answer my question. My homework assignment asks to find the complement of a negative number.. So instead of starting out with a positive, and needed to find out what its negative is, I am given a negative number and asked to find its complement. One silly thought is, do I find the positive value binary value, then flip the bits

Python - Obtain a list of numbers from a file and return as dict representation

帅比萌擦擦* 提交于 2019-12-02 21:47:57
问题 I'm having trouble reading from a file and returning the contents as a dictionary. Each file contains numbers separated by \n and the goal is to count the numbers returning each number as a key and the value of the key is the number of times it was in the file. Example: when filea.txt contains "1\n1\n1\n2\n3\n3\n3\n3\n5\n" the function should return {1:3,2:1,3:4,5:1} when filea.txt contains "100\n100\n3\n100\n9\n9\n" the function should return {100:3, 3:1, 9:2} when fileb.txt contains "13\n13