integer

Extract integers from string in Fortran

时光怂恿深爱的人放手 提交于 2020-01-16 19:40:54
问题 I'm using Fortran 90. I have a string declared as CHARACTER(20) :: Folds , which is assigned its value from a command line argument that looks like x:y:z where x, y, and z are all integers. I then need to pick out the numbers out of that string and to assign them to appropriate variables. This is how I tried doing it: i=1 do j=1, LEN_TRIM(folds) temp_fold='' if (folds(j).neqv.':') then temp_fold(j)=folds(j) elseif (i.eq.1) then read(temp_fold,*) FoldX i=i+1 elseif (i.eq.2) then read(temp_fold

Extract integers from string in Fortran

社会主义新天地 提交于 2020-01-16 19:40:52
问题 I'm using Fortran 90. I have a string declared as CHARACTER(20) :: Folds , which is assigned its value from a command line argument that looks like x:y:z where x, y, and z are all integers. I then need to pick out the numbers out of that string and to assign them to appropriate variables. This is how I tried doing it: i=1 do j=1, LEN_TRIM(folds) temp_fold='' if (folds(j).neqv.':') then temp_fold(j)=folds(j) elseif (i.eq.1) then read(temp_fold,*) FoldX i=i+1 elseif (i.eq.2) then read(temp_fold

iPhone Development: Global Variables

丶灬走出姿态 提交于 2020-01-16 19:06:32
问题 I am very new to Objective-C. I need to make a global variable. I have the files abc.h, abc.m, aaa.h, aaa.m and of course, the app delegate. I want to declare it in abc.h, use have the user assign it in abc.m and it be used in aaa.m. I want the variable to be an integer named x. I heard that I can use the App Delegate Somehow. I want the assigning variable in abc.m to be implemented in the middle of my code. Since I'm new, please make it simple!! Thanks in Advance! 回答1: You can use a property

How can i find a pattern in an array of integers?

不羁岁月 提交于 2020-01-16 09:03:29
问题 A week ago I got my homework, where I have to write a function in C. The function gets a single array of positive integers, and it has to return the next number in the array. The arrays look something like this: {1,2,3,1,2,3,4,1,2,3,1,2,3,4,1,2,3,-1}; -1 means the end of the array. I know that the number which has to be returned by the function is 1, however, how can I code a pattern finding algorithm? I haven't found any solution on the internet, since every other question about pattern

Reusing Java Scanner

不打扰是莪最后的温柔 提交于 2020-01-16 08:41:30
问题 Ive written a small Java code to calculate the product of two integers input by the user using Scanner. The user is forced to input integer values. The code is shown below. import java.util.Scanner; public class Principal { public static void main(String[] args) { int x=0,y=0; Scanner sc=new Scanner(System.in); //Asks for the first number until the user inputs an integer System.out.println("First number:"); while(!sc.hasNextInt()){ System.out.println("Not valid. First number:"); sc.nextLine()

Are the fast integer types faster when stored in the CPU registers?

不羁岁月 提交于 2020-01-16 08:39:30
问题 I have been thinking about the fast integer types: int_fast8_t , int_fast16_t , int_fast32_t , int_fast64_t , uint_fast8_t , uint_fast16_t , uint_fast32_t , uint_fast64_t over the last days and I asked a question about why (if so) these types are faster than the other integer types: Why are the fast integer types faster than the other integer types? Something I have further thought about now is, if : Faster types are faster on a certain environment (implementation/architecture-dependent) and

Appending ten digit integer to list concatenates some entries with an “L”

泪湿孤枕 提交于 2020-01-16 04:31:33
问题 I wrote a small script to find n-digit primes in the digits of e (in relation to that old Google ad): import math # First 251 digits of e e_digits = ("2" "7182818284 5904523536 0287471352 6624977572 4709369995" "9574966967 6277240766 3035354759 4571382178 5251664274" "2746639193 2003059921 8174135966 2904357290 0334295260" "5956307381 3232862794 3490763233 8298807531 9525101901" "1573834187 9307021540 8914993488 4167509244 7614606680") e_digits = e_digits.replace(" ", "") digits = int(raw

Performance loop with integer vs Long index

时光总嘲笑我的痴心妄想 提交于 2020-01-16 04:13:47
问题 I am wondering why it takes so much longer to run a loop with a long index vs. an integer index? Any idea? Thanks int n = 1000_000_000; long n2 =n; long t1 = System.currentTimeMillis(); for( int idx = 0; idx<n;idx++){ } long t2 = System.currentTimeMillis(); for( long idx = 0; idx<n2;idx++){ } long t3 = System.currentTimeMillis(); long dt1 = t2-t1; long dt2 = t3-t2; System.out.println("with int = took " + dt1 +"ms"); System.out.println("with long = took " + dt2 +"ms"); 回答1: It possible has

C - Read a single int at the time

北城以北 提交于 2020-01-16 02:55:05
问题 I have this input: Input: 2015 And I want to scanf him like this: scanf("%1d", &arr); But this is definitely wrong. What can I do? I want to receive the input integer by integer like '2','0','1','5' , and not like "2015". 回答1: Just read each character individually, and convert the individual char s to integers. #include <stdio.h> int main(int argc, char* argv[]) { size_t len, i; char buff[64]; fgets(buff, sizeof(buff), stdin); for(i = 0, len = strlen(buff); i < len; ++i) { int curr = buff[i]