当前位置:网站首页>暑期学前作业
暑期学前作业
2022-08-10 05:02:00 【米奇拉莫斯啦米老鼠】
1.插入排序
(1)
#include <stdio.h>
void print(int a[],int n)
{
for(int i=0;i<n;i++)
{
printf("%d",a[i]);
printf("\t");
}printf("\n");
}
void insertion_sort(int a[],int n)
{ print(a,n);
for(int i=1;i<n;i++)
{
int key=a[i];
int j=i-1;
while(j>=0&&a[j]>key)
{
a[j+1]=a[j];
j--;
}
a[j+1]=key;
print(a,n);
}
}
int main()
{
int a[1000];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
insertion_sort(a,n);
}
这种写法没有办法,无限输入,最近看书看到了vector,尝试的用c++写了一下,还没有搞懂vector做参数的做法,但是可以实现无限输入。
(2)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> a;
int n;
while(1)
{cin>>n;
a.push_back(n);
if(cin.get()=='\n')
break;
}
int len=a.size();
for(int i=1;i<len;i++)
{
int key=a[i];
int j=i-1;
while(j>=0&&a[j]>key)
{
a[j+1]=a[j];
j--;
}
a[j+1]=key;
for(int i=0;i<len;i++)
{
cout<<a[i]<<" ";
} cout<<endl;
}
}
2.输出二进制
#include <stdio.h>
void change(int x)
{if(x>0)
{change(x/2);
printf("%d",x%2);
}
}
int main()
{int x;
printf("Please input a number.\n");
scanf("%d",&x);
change(x);
}
3.判断素数
#include <stdio.h>
int judge(int x)
{
for(int i=2;i<=x-1;i++)
{if(x%i==0)
{
return 0;break;}
else continue;
}return 1;
}
int main()
{
int n;
int z=1;
while(z==1)
{ printf("Please input a number.\n");
scanf("%d",&n);
if(judge(n)==1)
printf("This is a prime number.\n ");
else printf("This is not a prime number.\n");
printf("If you want to continue please input 1 and if you want to stop please input 0.\n");
scanf("%d",&z);
}
printf("over");
}
4.支持La Tex的Markdown语句,编写数学公式

5.学习心得与期望
最近接触了Markdown,发现十分好用,在电脑上下载了Obsidian在里面下载了插件,拿来记一些代码笔记和数学笔记,就是还不太熟练用Markdown来写,还在慢慢摸索,至少最近效率提高了一些。期望是把知识学扎实了,多多思考,在数学方面由于个人原因,前面学期的学习内容都没有很好掌握,希望再接下来的假期时间,抓紧查漏补缺。
边栏推荐
- flinkcdc 读取pgsql 的时间被放大了 有大佬知道咋回事吗 gmt_create':1
- 如何从代码层提高产品质量
- 法定代表人和股东是什么关系
- JS获取当前时间的年、月、日、时间等
- LeetCode 2369. 检查数组是否存在有效划分 动态规划
- The time for flinkcdc to read pgsql is enlarged. Does anyone know what happened? gmt_create':1
- JVM内存模型
- Joomla漏洞复现
- JavsSE => 多态
- Using the DatePicker date control, Prop being mutated: "placement" error occurs
猜你喜欢

深度学习之-01

今天月亮很美

LeetCode·1413.逐步求和得到正数的最小值·贪心

2022G3 Boiler Water Treatment Exam Mock 100 Questions and Mock Exam

openvino 安装(01)

2022 security officer C certificate test and simulation test in shandong province

leetcode每天5题-Day12

【心理学·人物】第二期(学术X综艺)

什么是遗留代码:有效地处理遗留代码的8个小贴士

#【软件STM32cubeIDE下F103配置uart3+DMA收发+简单数据解析-基础样例】
随机推荐
音乐现场的未来将被NFT门票主宰?
解决“File has been changed outside the editor, reload?”提示
goland里的异常处理
About the problem that the mongodb driver count method of rust cannot be used with the near condition
From entry to mastery of PHPCMS imitation station, Xiaobai is enough to watch this set of courses
【论文笔记】Prototypical Contrast Adaptation for Domain Adaptive Semantic Segmentation
各位大佬,idea中测试使用FlinkCDC SQL 读取Mysql 数据写入Kafka中,代码中创
重要转型升级
BGP实验+选路+路由策略+OSPF
【u-boot】u-boot驱动模型分析(02)
GP如何进行数据比对?
oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
开发智能硬件过程中需要掌握的方法之经典
二进制中负数为何要用补码形式来表示——二进制加减法
取消了这次
Acwing 59. 把数字翻译成字符串 计数类DP
Order table delete, insert and search operations
栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
redis basic data types
SQL Server query optimization