算法入门(1)
来源:互联网 发布:剑网三李白脸型数据 编辑:程序博客网 时间:2024/06/05 09:56
最近在学习算法,所以想把所写的程序记录下来,程序比较简单,但是我相信始终会有帮助的
输入一个三位数,分离出它的百位,十位和个位,反转后输出
#include <stdio.h>#include <iostream>using namespace std;int main(){ int n; scanf("%d", &n); if (n%10==0) { printf("%d%d\n", n / 10 % 10, n /100); } else { printf("%d%d%d\n", n % 10, n / 10 % 10, n /100); } system("pause"); return 0;}
输入三个整数,从小到大输出
#include <stdio.h>#include <iostream>using namespace std;void comparethree(int &a, int &b, int &c);int main(){ int a,b,c,t; scanf("%d%d%d", &a,&b,&c); comparethree(a, b, c); printf("%d\t%d\t%d\n", a, b, c); system("pause"); return 0;}void comparethree(int &a, int &b, int &c){ int t; if (a>b) { t = a; a = b; b = t; } if (a>c) { t = a; a = c; c = t; } if (b > c){ t = b; b = c; c = t; }}
水仙花数
输出100-999中所有的水仙花数。若3位数ABC 满足ABC = A3+B3+C3,则称其为水仙花数。
#include <stdio.h>#include <iostream>using namespace std;int main(){ for (int i = 1; i <= 9; i++) { for (int j = 0; j <= 9; j++){ for (int z = 0; z <=9; z++) { int x = i*i*i; int y = j*j*j; int m = z*z*z; int s = i * 100 + j * 10 + z; if (s==x+y+m) { printf("%d\n", s); } } } } system("pause"); return 0;}
倒三角形
输入正整数,输出一个n层的倒三角形,例如n=5时输出如下:
######### ####### ##### ### ##include <stdio.h>#include <iostream>using namespace std;int main(){ int n; int count = 0; scanf("%d", &n); //输入层数 for (int i = n; i >=1; i--) 从顶层开始 { int s = 1 + 2 * (i - 1); //等差数列求得#数量 count++; for (int j = 0; j < s; j++) { printf("#"); } printf("\n"); for (int x = 0; x < count; x++) { printf(" "); //用于打印空格 } } system("pause"); return 0;}
0 0
- 算法入门(1)
- 算法入门(1)
- 算法入门1 (c语言)
- 算法竞赛入门经典(刘汝佳)1
- SVM算法入门详解(1)
- 数据结构与算法入门(1)--基本概念
- DP算法入门1
- 算法入门经典-1
- 算法入门1:基本概念
- 算法入门小结1
- 算法入门(0)
- 算法入门(一)
- 算法入门(2)
- 狄克斯特拉算法(入门)
- 0005 A*算法入门(寻路)【算法】
- Java小游戏算法入门(扑克牌算法)
- 遗传算法入门--连载1
- 算法入门--快速排序1
- ssh密钥登录认证自动配置脚本
- BZOJ1901: Zju2112 Dynamic Rankings
- IOS之UIViewController执行返回操作并传递参数值的两种方式
- hexo和github page联合搭建博客过程中,github上出现灰色文件的问题
- maven创建webapp项目
- 算法入门(1)
- 用于检测进程的shell脚本代码小结
- CentOS(5.8/6.4)linux生产环境若干优化实战
- POJ 2154 Color
- CURL常用命令
- 原生js实现无缝滚动
- 任务调度框架Quartz
- VLC 接收H264、TS、PS流SDP写法
- 将Eclipse代码导入到Android Studio的两种方式