def twonums(nums,target):
hashmap=dict()
for i in range(len(nums)):
if hashmap.get(target-nums[i]) is None:
hashmap[nums[i]]=i
else:
return [hashmap.get(target-nums[i]),i]
if __name__=='__main__':
nums=[4,3,7,9]
n=twonums(nums,11)
......................
阅读全部
|
qunxingw
贴于 2021年2月15日 09:44
hide
bbsi
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
bool file_exists(const char* file)
{
FILE* f = fopen(file, "r");
if (!f) {
return false;
}
......................
阅读全部
|
lvhui123456
贴于 2021年1月27日 15:57
hide
bbsi
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
bool file_exists(const char* file)
{
FILE* f = fopen(file, "r");
if (!f) {
return false;
}
......................
阅读全部
|
lvhui123456
贴于 2021年1月27日 15:56
hide
bbsi
// https://v.douyin.com/JTdQ2So/ 矗接觀看视频!
#include<stdio.h>
int A[9];
int a[9]={1,2,3,4,5,6,7,8,9};
int isok(int n)//分析A[]第N个数与前面的数比较为递归 作准备。
{
int flag=1,i;
for(i=0;i<n;i++){
if(A[n]==A[i]) flag=0;//不与前面已选择的数相同
......................
阅读全部
|
qunxingw
贴于 2021年1月26日 17:01
hide
bbsi
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void waiting(),stop();
int wait_mark;
void main() {
int p1,p2;
if (p1=fork()) { /*创建子进程 p1*/
if (p2=fork()) { /*创建子进程 p2*/
......................
阅读全部
|
blue1
贴于 2021年1月25日 19:51
hide
bbsi
#Python代码以实例展示求解方程的根。
import math
def f(x):
return math.pow(x,3)-9*x+1
def fd(x):
return 3*math.pow(x,2)-9
def newton_method(n,x):
times = n
next_x = 0
y= f(x)
yd = fd(x)
......................
阅读全部
|
qunxingw
贴于 2021年1月19日 09:56
hide
bbsi
#include<iostream>
#include <limits>
using namespace std;
int main()
{
cout << "type: \t\t" << "************size**************"<< endl;
cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
cout << "\t最大值:" << (numeric_limits<bool>::max)();
cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
cout << "char: \t\t" << "所占字节数:" << sizeof(char);
......................
阅读全部
|
水中风
贴于 2021年1月14日 17:16
hide
bbsi
#全排列
#arr 减一个元素,放入new_arr中
def allpai(arr,new_arr):
if len(new_arr)==4:
print(new_arr)
return
for i in range(len(arr)):
temp_new=new_arr+[arr[i]]
temp_arr=arr[:i]+ arr[i+1:]
allpai(temp_arr,temp_new)
......................
阅读全部
|
qunxingw
贴于 2021年1月11日 09:58
hide
bbsi