首页 文章 精选 留言 我的

精选列表

搜索[国密算法],共10000篇文章
优秀的个人博客,低调大师

c语言:输入任意10个正整数,按照升序排序输出:(冒泡算法

C语言永远不会过时 其实学编程关键是学习其思想,如果你精通了一门,再去学其他的时候也很容易上手。C不会过时的,尤其是在unix、linux操作平台上,学好C是必须的。 C跟C++在很多方面也是兼容的,c是c++的基础。 再者c能从很大的程度上帮你了解计算机的发展史,数据结构等方面的知识,很多软件、甚至操作系统中的很大部分是用c来实现的。 还有一些电器芯片的程序,比如电冰箱内制冷系统……可以说用c可以解决一切可能遇到的问题,关键是你要能精通它。 所以放开手脚去大胆的学吧,c永远不会过时 小编给大家推荐一个学习氛围超好的地方,C/C++交流企鹅裙:870963251!适合在校大学生,小白,想转行,想通过这个找工作的加入。裙里有大量学习资料,有大神解答交流问题,每晚都有免费的直播课程 源代码: #include<stdio.h> void main() { int a[10]; int i,m,n; printf("请输入10个正整数:\n"); for(i=0;i<10;i++) scanf("%d",&a[i]); printf("\n"); for(m=0;m<9;m++) /*进行9次循环 实现9趟比较*/ for(i=0;i<9-m;i++) /*在每一趟中进行9-m次比较*/ if(a[i]>a[i+1]) /*相邻两个数比较*/ { n=a[i]; a[i]=a[i+1]; a[i+1]=n; } printf("升序排列结果为:\n"); for(i=0;i<10;i++) printf(" %d",a[i]); printf("\n"); }

优秀的个人博客,低调大师

leetcode算法题解(Java版)-5-简单模拟,字符串处理

一、简单贪心 题目描述 Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the two endpoints of line i is at (i, ai ) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container. 思路 这题在一分钟内就想了个笨方法,迅速敲完,KO! 因为题目还是很简单,不考虑将装水的容器倾斜,所以只要考虑梯形中最短的边和底边的乘积就行了:正反两遍循环数组,第一遍从0~len,先固定最左边的边,从右往左遍历数组,如果碰到大于等于最左边边长的边,那就判断是否大于当前的最大盛水体积并跟新,然后就停止这次循环,将最左边的边向右移动一格,重复操作;第二遍从len~0,和第一遍一样。 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int maxW=0; for(int i=0;i<len;i++){ for(int j=len-1;j>i;j--){ if(height[j]>=height[i]){ if(height[i]*(j-i)>maxW){ maxW=height[i]*(j-i); } break; } } } for(int i=len-1;i>0;i--){ for(int j=0;j<i;j++){ if(height[j]>=height[i]){ if(height[i]*(i-j)>maxW){ maxW=height[i]*(i-j); } break; } } } return maxW; } } 思路2 好吧,虚心学习,看了一下其他人的代码。发现一个好方法: 从两边往中间走,每次舍弃较短的边,因为宽度减小,要通过高度的增加来弥补 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int l=0; int r=len-1; int maxW=0; while(l<r){ maxW=Math.max(maxW,Math.min(height[l],height[r])*(r-l)); if(height[l]<height[r]){ l++; } else{ r--; } } return maxW; } } 二、简单回文数字 题目描述 Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers.Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case? There is a more generic way of solving this problem. 思路 题目有个限制,就是不能开辟新的空间。 那就和一般的回文串做法不同了,可以这么来搞:干脆求出它翻转过来的整型,最后比较是否值相等。 想到这个思路,是因为int型的特殊基本数据类型,特别对待,哈哈哈 代码 public class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int reverse=0; int x_rel=x; while(x!=0){ reverse=reverse*10+x%10; x/=10; } return reverse==x_rel; } } 三、字符串,模拟 题目描述Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front. spoilers alert... click to show requirements for atoi.Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed. If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned. 思路 细节要求比较多,正负号,非法字符,溢出等都要考虑。 代码 public class Solution { public int atoi(String str) { if(str==null||str.length()==0){ return 0; } int pos=0; while(str.charAt(pos)==' '){ pos++; } int flag=1; if(str.charAt(pos)=='-'){ flag=-1; pos++; } if(str.charAt(pos)=='+'){ flag=1; pos++; } int len=str.length(); int res=0; for(int i=pos;i<len;i++){ char c=str.charAt(i); if(c<'0'||c>'9'){ break; } if(res>Integer.MAX_VALUE/10||(res==Integer.MAX_VALUE/10&&c>'7')){ if(flag>0){ return Integer.MAX_VALUE; } else{ return Integer.MIN_VALUE; } } res=res*10+(c-'0'); } return res*flag; } }

优秀的个人博客,低调大师

leetcode算法题解(Java版)-4-动态规划(杨辉三角问题)

一、简单模拟 题目描述 Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). 思路 肯定是低价买,高价卖出。但是有个限制就是在买进的时候,必须卖出手上的股票。 最低价买,最高价的时候卖。在递增数列中,末项减首项=每项与后一项之差的和。这里不需要考虑交易次数最小,所以可以这么写: 代码 public class Solution { public int maxProfit(int[] prices) { int len=prices.length; int maxPro=0; for(int i=1;i<len;i++){ if(prices[i]>prices[i-1]){ maxPro+=prices[i]-prices[i-1]; } } return maxPro; } } 二、模拟的升级版 题目描述 Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 思路 这题跟上一题不一样的地方在于,是能买卖一次了。 可以先固定局部最小值,后面不断维护跟新局部最大值和局部最小值的差,直到最后找到结果。 做了两道这种最大值和最小值差的问题,总结一下,因为最大值最小值都是在数组中变化的,所以可以考虑先固定出局部的最小值。 代码 import java.lang.Math; public class Solution { public int maxProfit(int[] prices) { int len=prices.length; if(prices==null||len==0){ return 0; } int min=prices[0]; int maxPro=0; for(int i=1;i<len;i++){ if(prices[i]<min){ min=prices[i]; } else{ maxPro=Math.max(prices[i]-min,maxPro); } } return maxPro; } } 三、动态规划 题目描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is11(i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle. 思路 经典的三角数组,动态规划问题 详细的请看代码。这里没有开辟新的存储,只是在最后一行上跟新维护每一行的最优解,最后最后一行的第一个数即为所求。 语法点:import java.util.ArrayList;ArrayList.get(index);ArrayList.set(index,value);import java.lang.Math;Math.min(value1,value2); 代码 import java.lang.Math; import java.util.ArrayList; public class Solution { public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) { int len=triangle.size(); if(len==0){ return 0; } if(len==1){ int min=triangle.get(0).get(0); for(int i=0;i<triangle.get(0).size();i++){ if(min>triangle.get(0).get(i)){ min=triangle.get(0).get(i); } } return min; } for(int i=len-2;i>=0;i--){ for(int j=0;j<i+1;j++){ int min=Math.min(triangle.get(len-1).get(j),triangle.get(len-1).get(j+1)); triangle.get(len-1).set(j,triangle.get(i).get(j)+min); } } return (int)triangle.get(len-1).get(0); } } 四、动态规划(杨辉三角) 题目描述 Given an index k, return the k th row of the Pascal's triangle. For example, given k = 3,Return[1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 思路 又是个动态规划问题,一开始想复杂了,或者说是没有按计算机思维来思考:我在算C{n_m},就是在算组合数,想通过组合数来打印出数组。 其实是个动态规划,当前行的值是依赖于上一行的。题目要求用O(n)空间来求解,那就设置了一个动态数组,每次从后往前刷新这个数组,即为所求。 代码 import java.util.ArrayList; public class Solution { public ArrayList<Integer> getRow(int rowIndex) { ArrayList<Integer> res=new ArrayList<>(); res.add(1); for(int i=0;i<rowIndex;i++){ for(int j=i;j>0;j--){//注意要从后往前刷新,因为用的是一个动态数组,防止仍有用的数据被新值覆盖 res.set(j,res.get(j)+res.get(j- 1)); } res.add(1); } return res; } }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册