当前位置:网站首页>The Martian - Simple Math Problems
The Martian - Simple Math Problems
2022-08-09 08:02:00 【scwMason】
The question is simply that five fingers represent 1 2 3 4 5, and then arrange them from small to large, and then calculate the largest number in the entire arrangement according to the second data given
Then the first thing we have to solve is: the order problem of sorting from small to large, here we can use two methods:
1. Handwritten code
2.STL function
The handwritten code mainly masters the following logic
1. First, look for two adjacent elements from the end, let the first element be *i, the second element be *ii, and satisfy *i<*ii.
2. After finding such a set of adjacent elements, check forward from the end to find the first element greater than *i, let it be *j, and swap the i and j elements (swap).
3. Reverse all elements after ii.
Then you can write the code:
#include#include#includeusing namespace std;int arr[10005],n,m;void work(){int flag;//find the first set of arr[i]=0;i--){if(arr[i]=0;i--){if(arr[i]>arr[flag]){int cur=arr[flag];arr[flag]=arr[i];arr[i]=cur;break;}}//Reverse all numbers after flagint left=flag+1,right=n-1;while(left<=right){int ds=arr[left];arr[left]=arr[right];arr[right]=ds;left++;right--;}}int main(){scanf("%d%d",&n,&m);for(int i=0;i
If you use STL functions, you can:
#include#include#includeusing namespace std;int arr[10005],n,m;}int main(){scanf("%d%d",&n,&m);for(int i=0;i
The principle is the same
边栏推荐
- (四)BP神经网络预测(上)
- Luogu P1110 report statistics multiset stl good question
- 【机器学习】降维代码练习
- One-click login server script
- String类创建的对象在JVM中的内存分配和equals与==的区别
- CoCube传感器MPU6050笔记
- C language: reverse character order
- 如何把无用的代码注释为 Deprecated 弃用
- Anaconda replaces the default virtual environment
- Unity 3D模型展示框架篇之资源打包、加载、热更(二)
猜你喜欢
随机推荐
SOLIDWORKS Simulation教程:计算物体的固有频率
C#高级学习1
原生JDBC操作数据库
接口测试概念
VOC format label to YOLO format
[STL]vector
如何生成dll文件 采用VS2017生成dll文件(动态库文件)和lib文件(静态库文件)以C语言为例
梅科尔工作室--BP神经网络培训笔记
Web 3D渲染引擎HOOPS Communicator动画编辑器的使用 | HOOPS教程
Snake game, C language
db2数据库备份恢复问题
LeetCode: 876. The middle node of the linked list —— simple
[STL]list
图像处理(一)图像基础
Exclude null values when Oracle limits
LeetCode:876. 链表的中间结点————简单
resourcemanager启动失败,别的节点成功
IDEA文件UTF-8格式控制台输出中文乱码
EXCEL uses function joint debugging (find, mid, vlookup, xlookup)
VOC格式标签转YOLO格式