(Google interview question) There are four threads 1, 2, 3, and 4. The function of thread 1 is to output 1, the function of thread 2 is to output 2, and so on… There are now four files ABCD. Initially they are empty.

Now we want the four files to be in the following format: A:1 2 3 4 1 2…. B:2 3 4 1 2 3…. C:3 4 1 2 3 4…. D:4 1 2 3 4 1…. Please design a program. The following is an example of A. For B, C, and D, you only need to modify the initialization value of the global variable n: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 pthread_mutex_t myloack=PTHREAD_MUTEX_INITIALIZER; 7 pthread_cond_t mycOnd=PTHREAD_COND_INITIALIZER; 8 int n=0; 9 void *ThreadFunc(void *arg) 10 { 11 int num=(int )arg; 12 for (int i = 0; i <10 ; ++i) 13 { 14 pthread_mutex_lock(&myloack); 15 while (n!=num) 16 pthread_cond_wait(&mycond,&myloack); 17 18 if (num==0) 19 cout<<“1”; 20 else if(num==1) 21 cout<<“2”; 22 else if(num==2) 23 cout<<“3”; 24 else 25 cout<<“4″<<endl; 26 n=(n+1)%4; 27 pthread_mutex_unlock(&myloack); 28 pthread_cond_broadcast(&mycond); 29 } 30 return (void *)0; 31 } 32 33 int main(int argc, char const *argv[ ]) 34 { 35 36 pthread_t id[4]; 37 for (int i = 0; i <4 ; ++i) 38 { 39 int err=pthread_create(&id[i],NULL,ThreadFunc,(void *)i); 40 if (err!=0) 41 { 42 cout<<“create err:”<<endl; 43 exit(-1); 44 } 45 46 } 47 48 for (int i =…

Insert image description here

weightofsize[64,3,7,7],expectedinput[1,4,512,1024]tohave3channels,butgot4channels

For the record only,Please skip. After the blogger’s article,The blogger opened a new picture,After feeding the model-this problem occurred again:weight of size [ 64, 3, 7, 7], expected input[1, 4, 512, 1024] to have 3 channels, but got 4 channels instead That is, the original three-channel picture&#xff0c ; After reading, it becomes four channels. Solution Add .convert('RGB'),Yes Image.open functionCaused That’s it. Thanks to the big blogger for the article :Portal

Technology Sharing

Let’s talk about the various levels of GoogleTestCertified in detail-Level2,3

Please contact the author for reprinting, thank you! ​ No releases with red testsBased on continuous integration built at Level 1, the CL (changelist) selected for continuous release can be taken from the last CL run through the CI system, because continuous integration includes smoke tests, then A system is released to a development or test environment where testing focuses on other categories of use cases. Require smoke test suite to pass before a submitThe smoke test suite has been divided into Level 1. After each code review passes, the developer will run the smoke test again before submitting the code, thus ensuring that every The smoke test passed every time the code was submitted, saving the cost of later repairs. (I don’t know if you have ever encountered a developer who was notified that the test can be tested after submitting the code, but you encountered problems as soon as you accessed the system, so similar BVT is mandatory and pushed to every code submission)Code review The tool can define rules. Only after passing the smoke test can the code be successfully submitted to the code base. If it fails, an email will be sent to the development. ​…

Insert picture description here

Use Java simulation to implement disk array raid levels 0, 1, 3, 5, 6, 01, 10

Table of contents 1. Instructions for use 2. Overall design 3. Operation screenshots 4. Detailed design 4.1raid0 4.2raid1 4.3raid3 4.4raid5 4.5raid6 4.6raid01 4.7raid10 5. Source code 1. Instructions for use The development environment of this program is the Windows operating system Eclipse software – developed using Java language. When using, open the project file and run Main.java under the raidMain package. According to the prompts, enter the file to be written “full path of the file” and the file to be read. The entered file path indicates file reading. The saved path “contains the file name to be read” and the file can be restored. The disk “folder” used by each disk array level data is different. For example, the main disk path of raid0 is disk/raid0 and raid6 is disk/raid6. The other disk/read and disk/read are used to demonstrate the file path for writing and reading. Of course, you can also choose other files for operation. Data when the disk is damaged when raid3, 5, and 6 are not completed. Restoration: After writing, I still found that there were still big problems with the program structure. However, the changes took a lot of time and I just let it…

java11235_Use java to calculate the sum of the 120th digit of 1,1,2,3,5,8…

Use java to calculate the sum of the numbers 1, 1, 2, 3, 5, 8… 1-20th digits Attention: 254 Answer: 4 mip version Solution time 2021-01-27 00:01 The questioner is sorry and sorry 2021-01-26 16:29 Use java to calculate 1,1,2,3,5 ,8…The sum of the 1-20th digits Best answer Second-level knowledge expert Takaki Nono 2021-01-26 16:54 public class Test1 { public static void main(String args[]) { int a[] = new int[20]; a[0] = a[1] = 1; int sum = a[0] + a[1]; for (int i = 2; i <20; i++) { a[i] = a[i – 2] + a[i – 1]; sum += a[i]; } System.out.println(” The sum of the first 20 digits is :” + sum); } } The result is :17710 Answer all 1F Liuli Zhishi 2021-01-26 19:27 If you observe the rules of numbers, you will know that except for the first number And the second number is unexpected, the other numbers are equal to the first 2 numbers, and I wrote a function to see if you want to see it, but I didn’t pay much attention to the function name (I am a novice) //———– ——–Function class——————————— package com.yaojian.com; public class hanshu { public int feibulaji(int n){…

How many implementation codes that are different from each other and do not have repeated numbers can be composed by Java1,2,3,4

Question: There are 1, 2, 3, and 4 numbers. How many different three-digit numbers can be formed without repeated numbers? How many are they? Program analysis: The numbers that can be filled in the hundreds, tens, and ones places are all 1, 2, 3, and 4. After composing all the permutations, remove the permutations that do not meet the conditions. Programming: public class Wanshu { public static void main(String[] args) { int i=0; int j=0; int k=0; int t=0; for(i=1;i<=4;i++) for(j=1;j<=4;j++) for(k=1;k<=4;k++) if(i!=j && j!=k && i!=k) {t+=1; System.out.println(i*100+j*10+k); } System.out.println (t); } }

Insert picture description here

Use Java simulation to implement disk array raid levels 0, 1, 3, 5, 6, 01, 10

Table of contents 1. Instructions for use 2. Overall design 3. Operation screenshots 4. Detailed design 4.1raid0 4.2raid1 4.3raid3 4.4raid5 4.5raid6 4.6raid01 4.7raid10 5. Source code 1. Instructions for use The development environment of this program is the Windows operating system Eclipse software – developed using Java language. When using, open the project file and run Main.java under the raidMain package. According to the prompts, enter the file to be written “full path of the file” and the file to be read. The entered file path indicates file reading. The saved path “contains the file name to be read” and the file can be restored. The disk “folder” used by each disk array level data is different. For example, the main disk path of raid0 is disk/raid0 and raid6 is disk/raid6. The other disk/read and disk/read are used to demonstrate the file path for writing and reading. Of course, you can also choose other files for operation. Data when the disk is damaged when raid3, 5, and 6 are not completed. Restoration: After writing, I still found that there were still big problems with the program structure. However, the changes took a lot of time and I just let it…

java11235_Use java to calculate the sum of the 120th digit of 1,1,2,3,5,8…

Use java to calculate the sum of the numbers 1, 1, 2, 3, 5, 8… 1-20th digits Attention: 254 Answer: 4 mip version Solution time 2021-01-27 00:01 The questioner is sorry and sorry 2021-01-26 16:29 Use java to calculate 1,1,2,3,5 ,8…The sum of the 1-20th digits Best answer Second-level knowledge expert Takaki Nono 2021-01-26 16:54 public class Test1 { public static void main(String args[]) { int a[] = new int[20]; a[0] = a[1] = 1; int sum = a[0] + a[1]; for (int i = 2; i <20; i++) { a[i] = a[i – 2] + a[i – 1]; sum += a[i]; } System.out.println(” The sum of the first 20 digits is :” + sum); } } The result is :17710 Answer all 1F Liuli Zhishi 2021-01-26 19:27 If you observe the rules of numbers, you will know that except for the first number And the second number is unexpected, the other numbers are equal to the first 2 numbers, and I wrote a function to see if you want to see it, but I didn’t pay much attention to the function name (I am a novice) //———– ——–Function class——————————— package com.yaojian.com; public class hanshu { public int feibulaji(int n){…

Java loop exercise: There are four numbers 1, 2, 3, and 4. How many three-digit numbers without repeating numbers can be formed? How many are they?

package practiceGO; /** There are four numbers 1, 2, 3, and 4. How many three-digit numbers without repeating numbers can be formed? How many are they? */ public class Cto { public static void main(String[] args) { int count = 0; for(int i=1; i<=4; i++){ for(int j=1; j<=4; j++){ for(int k=1; k<=4; k++){ if (i!=j && i!=k && j!=k) { System.out.println(i*100+j*10+k); count++; } } } } System.out.println("can form "+count+" non-repeating three-digit numbers"); } } Run result: 123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432 Can form 24 non-repeating three-digit numbers Java loop exercise: There are four numbers 1, 2, 3, and 4. How many non-repeating numbers can be formed? three digits? How many are they?

Passing 2 values ​​when accessing values ​​in javascript array “myArray[1,3]”

I realize this is incorrect syntax, but why does Javascript ignore the first number and give a response instead of destroying? let myArray = [1,2,3,4] myArray[0,1] // 2 myArray[1,3] // 4 myArray[3,0] // 1 pushkin.. 5 This is not incorrect syntax. This is just the comma operator. From docs: The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand. For example, [1,2][1,2], perhaps strangely, will return undefined. Why? The second [ is interpreted by the compiler as an array subscript operator because the semantics of Javascript do not allow two arrays to be adjacent to each other. Thus, the second 1,2 must be an expression that evaluates to the index. 1,2 causes the first operand to be evaluated, and then The second operand, this is what is returned. So it uses index 2 which of course does not exist in that array and we get undefined. 1> pushkin..: This is not incorrect syntax. This is just the comma operator. From docs: The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand. For example, [1,2][1,2], perhaps strangely, will return undefined. Why?…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索