暑假代码小练
文章平均质量分 51
Beautyxxi
想要强到可以无所顾虑、随心做选择。
展开
-
如何判断一个数是不是回文数
回文数:正着写和倒着写都一样的数字。eg:12321,23432等。举例:从键盘输入一个数字,如果该数字是回文数,则返回yes,否则返回 no。# include <stdio.h>int main(){ int val; int m; int sum = 0; printf("请输入您需要判断的数:"); scanf("%d", &val); m = val; while (m) //m只要不为零就继续执行 { sum = sum*10 +原创 2020-08-11 15:06:21 · 1401 阅读 · 2 评论 -
暑假代码 LeetCode 1 两数之和
LeetCode1、两数之和 题目描述:给定一个整数数组 nums 和一个目标值 target,在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1]思路一:假设一个是a,另一个就是target-a。(明明是第一题,还是两数之和,还不按常理出牌简单一点,写代原创 2020-08-02 15:02:42 · 132 阅读 · 0 评论 -
暑假代码 HDU oj1000 A+B problem
HDU oj1000Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2代码如下:#include <iostream>using namespace std;原创 2020-08-02 11:57:52 · 97 阅读 · 0 评论 -
暑假代码:判断一个数是不是2的幂次方
判断一个数是不是2的幂次方两种方法~原创 2020-07-29 21:44:45 · 183 阅读 · 0 评论