user-input

Does closing Scanner affect performance

人走茶凉 提交于 2019-12-23 12:42:48
问题 I was solving a competitive problem and in problem, I was taking user input using scanner. These are 2 code segments, one closing scanner and one without closing scanner. Closing scanner import java.util.Scanner; public class JImSelection { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.valueOf(scanner.nextLine()); while (n-- > 0) { double number = (Math.log(Long.valueOf(scanner.nextLine())) / Math.log(2)); System.out.println((int) number -

Preparing user-defined search term(s) for query

梦想的初衷 提交于 2019-12-23 08:04:23
问题 For a search feature I wrote a MySQL query to be executed by a PHP script. I'm not doing a fulltext search. Instead, I'm doing a search using the following method: ... WHERE field LIKE '%etc%' AND field REGEXP '[[:<:]]etc[[:>:]]' Now, my idea is to prepare these dynamic values in PHP, like: $word = '2*3%5_1^0'; // just an example $wordLike = strtr($word,array('\\'=>'\\\\','%'=>'\\%','_'=>'\\_')); // instead of my old solution: // $wordLike = preg_replace('~([%_])~', '\\\\$1', $word);

PHP: Saving multiple input fields in rows based on ID or date of row

。_饼干妹妹 提交于 2019-12-23 05:15:10
问题 I'm not entirely certain how descriptive that title is, but: In Wordpress I have a custom table of numerical data which gets added to monthly (via a spreadsheet import). As such, I'm using $wpdb to pull the contents of that table, which gets returned as an array of stdClass objects: Array ( [0] => stdClass Object ( [id] => 553 [assocID] => 1 [title] => Afghanistan [weight_political] => 8.2 [indicator_political] => 0.0 [weight_security] => 9.5 [indicator_security] => 0.0 [weight_criminal] => 9

Asking user for information, and never having to ask again

时光毁灭记忆、已成空白 提交于 2019-12-23 04:40:20
问题 I want to ask for user input, but I only want to do it once (possibly save the information within the program), meaning, something like this: print "Enter your name (you will only need to do this once): " name = gets.chomp str = "Hello there #{name}" #<= As long as the user has put their name in the very first # time the program was run, I want them to never have to put thier name in again How can I got about doing this within a Ruby program? This program will be run by multiple users

C++ Detecting ENTER key pressed by user

我们两清 提交于 2019-12-23 04:27:03
问题 I have a loop where I ask the user to enter a name. I need to stop when the user presses the ENTER key..... or when 20 names have been entered. However my method doesn't stop when the user presses the ENTER key //loop until ENTER key is entered or 20 elements have been added bool stop = false; int ind = 0; while( !stop || ind >= 20 ){ cout << "Enter name #" << (ind+1) << ":"; string temp; getline(cin, temp); int enterKey = atoi(temp.c_str()); if(enterKey == '\n'){ stop = true; } else{ names

BlackBerry LongClickListener implementation

旧时模样 提交于 2019-12-23 04:26:29
问题 I need to implement OnLongClickListener for BlackBerry platform. It may be used for user input (ex phone keyboard implementation) or other functionality (navigation, rewind control, zoom control, etc). There are requirements: target control to listen - custom ButtonField it should be version compiliant with 4.5 and 4.6, so no touchEvents etc. configurable long click time Do you have some suggestions about concept and implementation? Also, what issues I can get in using multiple listeners for

C code for ignoring the enter key after input

断了今生、忘了曾经 提交于 2019-12-22 12:39:08
问题 I am having a problem with the Enter key or character in the stdin stream messing up following input calls. let's say I have one input call, so I enter in the stuff. but then takes the Enter key as input for the next input call. I think in c++ there is cin.ignore() to do the trick. I just can't find the C version. The input methods are getchar() and gets() . Sorry if this is a duplicate. I couldn't find the question that matches mine. thanks for any help! printf("Do you want to view the lines

How can I read multiple lines of user input in AutoHotkey?

寵の児 提交于 2019-12-22 10:27:26
问题 I have an AutoHotkey script which needs to read multiple lines of employee data from a user. InputBox, userInput, Employee Records, Please enter employee records. (One per line) Unfortunately, an InputBox only allows users to enter a single line of text. Trying to add newlines with Enter will instead submit whatever data has been entered. How can I take in multiple lines of user input in an AutoHotkey script? 回答1: This implements a generic multiline input function F3::MsgBox % MultiLineInput(

Java Scanner does not wait for input

Deadly 提交于 2019-12-22 08:54:10
问题 I have two blocks of code here. One scanner properly waits user input, and the other just blows right through it and calls nextInt() which returns a NoSuchElementException . Here is the block that works: public void startGame() { out.println("Player1: 1 for dumb player, 2 for smart player, 3 for human player."); Scanner scan = new Scanner(System.in); p = scan.nextInt(); if (p == 1) p1 = new DumbPlayer("ONE"); if (p == 2) p1 = new SmartPlayer("ONE"); else p1 = new HumanPlayer("ONE"); out

Prevent screen from sleeping with C#

微笑、不失礼 提交于 2019-12-22 06:48:34
问题 I have created a small C# console app to move the pointer around the screen, in the hope that this would prevent the screen from sleeping / locking after a few minutes. Unfortunately the screen still goes to sleep after a few minutes. Does anyone know if it's actually possible to write something in C# which will act like user input (either mouse or keyboard), and prevent the screen from sleeping / locking automatically? Here is what I have, which I thought might do the trick. class Program {