- 博客(17)
- 资源 (1)
- 收藏
- 关注
原创 clj 10以下的自然数中,属于3或者5的倍数的有3,5,6和9,它们之和是23.找出1000以下的自然数中,属于3或者5的倍数的数字之和
第一种方法(reduce + (set (concat (range 0 1000 3) (range 0 1000 5))))第二种方法(defn sb [n] (reduce + (for [x (range n) :when (or (= (mod x 3) 0) (= (mod x 5) 0))] x)))(sb 1000)...
2021-11-20 09:18:35 253
原创 (更新后的解法)允许并列的排名
#include "stdio.h"void main(){ int N,m,i,x,d=0,j,temp; int a[100]; scanf("%d",&N); for(i=0;i<N;i++) scanf("%d",&a[i]); scanf("%d",&m); for(i=0;i<N-1;i++) { for(j=0;j<N-1-i;j++) { if(a[j]<a[j+1]) { .
2021-11-18 20:36:44 2071 4
原创 允许并列的排名(维克特利奥特曼,这位作者,你要的解答来了)
#include<bits/stdc++.h>using namespace std;int a,b[1000],c;int main(){ cin>>a; for(int i=1;i<=a;i++) cin>>b[i]; cin>>c; for(int i=1;i<=a;i++) for(int j=i;j<=a;j++) if(b[i]<b[j]) swap(b[i],b[j]); for(.
2021-11-17 19:45:23 627 12
原创 html 制作一个有趣的小网站
!DOCTYPE html><html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="yang" style="font font-size:15px;color:brown;">请为文字选择颜色和字号</div> ...
2021-11-17 19:36:19 2692
原创 clj 写代码,去除重复的值,保留一个,能达到如下效果;;[“a“ “a“ “zm“ “zm“ “zm“ 1 2 3 3 3] => [“a“ “zm“ 1 2 3]
(into [] (map first (partition-by identity ["a" "a" "zm" "zm" "zm" 1 2 3 3 3])))
2021-11-14 11:18:16 209 2
原创 clj 定义一个原子向量,初始为空 brothers 将你们几兄弟加入到brothers中,每个兄弟用一个map映射表来表示,有name,age
(def brothers (atom {}))@brothers(swap! brothers assoc 1 {:id 1 :name "wrl" :age 10} 2 {:id 2 :name "wrj" :age 9} 3 {:id 3 :name "zrj" :age 9} 4 {:id 4 :name "wrp" :age 12})
2021-11-13 16:08:36 189
原创 clj 将字符串 “a,b,c,d“ 转换为 {:A a1 :B b1 :C c1}
(def s "a,b,c,d")(let [vs (str/split s #",") ks (map #(keyword (str/upper-case %)) vs) vs1 (map #(str % 1) vs) ] (dissoc (zipmap ks vs1) :D))
2021-11-13 16:02:42 699
原创 clj 小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一个猜。他们一共进行三次这个游戏,请返回 小A 猜对了几次?输入的guess
第一种解法(defn game [guess answer] (count (for [i (range 3) :when (= (guess i) (answer i))] i)))第二种解法(defn game1 [guess answer] (->> (map = guess answer) (filter true?) (count )))...
2021-10-30 20:30:33 1699 1
原创 clj 编写一个函数two-sum 求出两数之和给定一个整数数组 nums和一个整数目标值target请你在该数组中找出和为目标值 target 的那 两个 整数并返回它们的数组下标。
(defn two-sum [nums targer] (let [length (count nums)] (first (for [i (range 0 length) j (range 0 length) :when (and (not= i j) (= targer (+ (nums i) (nums j)))) ] [i j] )).
2021-10-29 21:28:58 222
原创 C++ 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。
#include<stdio.h> int main() { int nums[] = {2, 7, 11, 15}; int n = 4; int target, i, j; int result[] = {-1, -1}; printf("nums=[%d, %d, %d, %d]\n", nums[0], nums[1], nums[2], nums[3]); printf("请输入目标:"); scanf("%d",.
2021-10-07 18:42:58 3568
原创 clojure clj 将[2 5 4 1 3 6 10 56 89]第7、8个元素减1后,再求和
(->> [2 5 4 1 3 6 10 56 89] (drop 6) (take 2) (map #(- % 1)) (reduce +))
2021-10-06 19:04:16 58
原创 clojure clj随机生成50个整数,这50个整数都在1000以内
第一种解法(take 20 (repeatedly #(rand-int 100)))第二种解法(repeatedly 50 #(rand-int 1000))箭头红(->> (repeatedly #(rand-int 100)) (take 20))
2021-10-06 19:02:39 110
原创 c++ ----列朋波骨
#include <iostream>using namespace std;int main(int argc, char *argv[]){ int i; i=0; i=i+1; i=i+1; i=i+1; i=i+1; i=i+1; cout << i; return 0;}
2021-10-06 11:46:59 304
原创 c++ -----你给它输进什么它就输出什么
#include <iostream>using namespace std;int main(int argc, char *argv[]){ int m; cin >> m << endl; return 0;}
2021-10-06 11:41:45 115
原创 clojure clj 写一个函数remove-dup,去除重复的数,保留一个,能达到如下效果. (remove-dup [1 1 1 3 3 5 7 7 9]) => (1 3 5 7 9)
(map first (partition-by identity [1 1 1 3 3 5 7 7 9]))
2021-10-05 17:35:10 85
原创 c++ 精益求精 —————分数化为小数
#include <iostream>using namespace std;int main(int argc, char *argv[]){ cout << 1/7 << endl; cout << 1.0/7 << endl; cout << (double)1/7 << endl; return 0;}
2021-10-05 17:28:35 238
原创 天安门广场 ————变量、表达式
#include <iostream>using namespace std;int main(int argc, char *argv[]){ int a,b,s; a=880 b=500 s=a*b cout << "天安门广场面积"; cout << s << "平方米"; return 0;}
2021-10-05 17:07:58 325
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人