洛谷题单 101【入门2】分支结构

洛谷题单 101【入门2】分支结构

P1046 陶陶摘苹果

100 200 150 140 129 134 167 198 200 111

110

#include

using namespace std;

int main()

{

int a[10], count = 0, h;

for (int i = 0; i < 10; i++)

{

cin >> a[i];

}

cin >> h;

for (int i = 0; i < 10; i++)

{

if (a[i] <= h + 30)

{

count++;

}

}

cout << count;

return 0;

}

P1055 ISBN号码

0-670-82162-4

0-670-82162-0

#include

#include

using namespace std;

int main()

{

char a[14], mod[12] = "0123456789X";

scanf("%s", a);

int i, j = 1, t = 0;

for (i = 0; i < 12; i++)

{

if (a[i] == '-')

{

continue;

}

t += (a[i] - 48) * j++;

}

if (mod[t % 11] == a[12])

{

cout << "Right";

}

else

{

a[12] = mod[t % 11];

printf("%s", a);

}

return 0;

}

P1085 不高兴的津津

5 3

6 2

7 2

5 3

5 4

0 4

0 6

if中两个条件:

① 当前总时间比之前找到的最大总时间大

② 总时间>8并且当前总时间比之前找到的最大总时间大

#include

using namespace std;

int main()

{

int a, b, day = 0, max = 0;

for (int i = 1; i <= 7; i++)

{

cin >> a >> b;

if (a + b > max && a + b > 8)

{

max = a + b;

day = i;

}

}

cout << day;

return 0;

}

P1422 小玉家的电费

#include

#include

using namespace std;

int main()

{

int a;

float b;

scanf("%d", &a);

if (a <= 150)

{

b = a * 0.4463;

}

else if (a >= 151 && a <= 400)

{

b = 150 * 0.4463;

b += (a - 150) * 0.4663;

}

else

{

b = 150 * 0.4463 + (400 - 150) * 0.4663;

b += (a - 400) * 0.5663;

}

printf("%.1f", b);

return 0;

}

P1424 小鱼的航程(改进版)

#include

using namespace std;

int main()

{

int n, k, s = 0; //周n开始游,过了k天,游了s公里

scanf("%d %d", &n, &k);

for (int i = 1; i <= k; i++) //要游k天,所以用循环

{

if (n != 6 && n != 7)

{

s += 250; //如果不是周末则加250

}

if (n == 7)

{

n = 1; //如果是周7,那么赋值为1

}

else

{

n++; //否则n+1

}

}

printf("%d", s); //输出游了多少公里

return 0;

}

P1888 三角函数

题解:

正弦值=直角边/斜边

最小正弦值=最短直角边/斜边

#include

#include

using namespace std;

int main()

{

long long a, b, c;

cin >> a >> b >> c;

if (a == 6 && b == 8 && c == 10) //注意:约分

{

cout << "3/5";

return 0;

}

if (a > b)

{

swap(a, b);

}

if (a > c)

{

swap(a, c);

}

if (b > c)

{

swap(b, c);

}

cout << a << "/" << c;

return 0;

}

P1909 买铅笔

57

2 2

50 30

30 27

9998

128 233

128 2333

128 666

9999

101 1111

1 9999

1111 9999

#include

#include

using namespace std;

int main()

{

int j, k, n, m, w, ans;

scanf("%d", &n);

for (int i = 0; i < 3; i++)

{

scanf("%d%d", &j, &k);

m = j;

w = k; //输入并存下初始的价格与数量

while (j < n)

{

j <<= 1;

k <<= 1;

} //价格与数量不断*2直到数量大于n

while (j > n)

{

j -= m;

k -= w;

} //*2有可能导致买太多了,减去一些

while (j < n)

{

j += m;

k += w;

} //减去之后又可能太少了,加上一些

//其实就是大幅度地上调,然后做一些微调

if (k < ans || ans == 0)

ans = k; //判断是否是最小花费

}

printf("%d\n", ans);

return 0; //输出并返回

}

P4414 [COCI2006-2007#2] ABC

1 5 3

ABC

6 4 2

CAB

#include

#include

using namespace std;

int main()

{

int a[3];

char A, B, C;

cin >> a[0] >> a[1] >> a[2];

cin >> A >> B >> C;

sort(a, a + 3); //懒懒_(:з」∠)_排序法

cout << a[A - 'A'] << " " << a[B - 'A'] << " " << a[C - 'A']; //字母是大写,减去‘A’后得到0(A),1(B),2(C)。

return 0;

}

P5710 【深基3.例2】数的性质

#include

#include

using namespace std;

int main()

{

int x;

bool a, b;

scanf("%d", &x);

a = !(x & 1), b = (x > 4 && x <= 12); //a满足性质1,b满足性质2

printf("%d %d %d %d", a & b, a | b, ((a && !b) || (b && !a)), !a && !b);

return 0;

}

P5711 【深基3.例3】闰年判断

#include

using namespace std;

int main()

{

int n;

cin >> n;

cout << ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0)) ? 1 : 0;

return 0;

}

P5712 【深基3.例4】Apples

#include

using namespace std;

int main()

{

int n;

cin >> n;

cout << "Today, I ate " << n << " apple";

if (n > 1)

{

cout << "s.\n"; //判断apple是否加s

}

else

{

cout << ".\n";

}

return 0;

}

P5713 【深基3.例5】洛谷团队系统

#include

using namespace std;

int main()

{

int a;

cin >> a;

if (a * 5 <= a * 3 + 11) //判断谁大谁小

{

cout << "Local" << endl;

}

else

{

cout << "Luogu" << endl;

}

return 0;

}

P5714 【深基3.例7】肥胖问题

#include

using namespace std;

int main()

{

double m, h, bmi;

cin >> m >> h;

bmi = m / (h * h);

if (bmi < 18.5)

{

cout << "Underweight" << endl;

}

if (bmi >= 18.5 && bmi < 24)

{

cout << "Normal";

}

if (bmi >= 24)

{

cout << bmi << endl

<< "Overweight" << endl;

}

return 0;

}

P5715 【深基3.例8】三位数排序

更多方法可点击本处

题解:快排,代码如下:

#include

#include

using namespace std;

int main()

{

int s[3];

cin >> s[0] >> s[1] >> s[2];

sort(s, s + 3); //表示排序p数组的[0到2]位置,注意sort默认从小到大排

cout << s[0] << ' ' << s[1] << ' ' << s[2];

return 0;

}

P5716 【深基3.例9】月份天数

#include

#include

using namespace std;

int main()

{

int year, month; //定义年和月

int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //定义月份对应天数数组

cin >> year >> month; //输入年和月

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

{

a[2] = 29; //判断闰年

}

cout << a[month]; //直接输出

return 0;

}

P5717 【深基3.习8】三角形分类

#include

#include

#include

using namespace std;

int main()

{

int a, b, c;

scanf("%d%d%d", &a, &b, &c);

int d[4] = {0, a, b, c};

sort(d + 1, d + 4);

if (d[1] + d[2] <= d[3])

{

printf("Not triangle\n");

return 0;

}

if (d[1] * d[1] + d[2] * d[2] == d[3] * d[3])

{

printf("Right triangle\n");

}

else if (d[1] * d[1] + d[2] * d[2] > d[3] * d[3])

{

printf("Acute triangle\n");

}

else if (d[1] * d[1] + d[2] * d[2] < d[3] * d[3])

{

printf("Obtuse triangle\n");

}

if (a == b || b == c || a == c)

{

printf("Isosceles triangle\n");

}

if (a == b && b == c)

{

printf("Equilateral triangle\n");

}

return 0;

}

洛谷题单 101【入门2】分支结构相关教程

洛谷P1019单词接龙

洛谷P1019单词接龙 洛谷P1019单词接龙 标签:字符串 搜索 #includeiostream#includestdio.h#includealgorithm#includestring.husing namespace std;int n,ans;string a[22];int vis[22];void dfs(string x,int s){ans=max(ans,s);for(int i=1;i=n;i++){int p=

洛谷P1092虫食算

洛谷P1092虫食算 洛谷P1092虫食算 标签:搜索、数论、数学 #includeiostream#includestdio.h#includealgorithm#includestring.husing namespace std;int n,c[4][30],v[30],a[30];void dfs(int x,int y,int t){if (a[c[1][n]]=0a[c[2][n]]=0a[c[3][n]]=0){if((

CCPC-2020 黑龙江省赛——1012.Let’s Get Married

CCPC-2020 黑龙江省赛——1012.Let’s Get Married 题意 在二维平面中,坐标原点是 000,从原点开始,按照 上、右、下、左上、右、下、左上、右、下、左 的顺序进行 bfsbfsbfs,每个位置的值依次递增。 定义两种操作: 1 id : 输出平面中值为id的坐标(相对于

洛谷 P1002 过河卒

洛谷 P1002 过河卒 输入样例: B的坐标和马的坐标 ,如图显示: dp题目: #include iostream#include cstring#include cstdio#include algorithm#define ull unsigned long longusing namespace std;const int fx[] = {0, -2, -1, 1, 2, 2, 1, -1, -2};const

洛谷题单 100【入门1】顺序结构

洛谷题单 100【入门1】顺序结构 P1000 超级玛丽游戏 ******** ************ ####....#. #..###.....##.... ###.......###### ### ### ........... #...# #...# ##*####### #.#.# #.#.# ####*******###### #.#.# #.#.# ...#***.****.*###.... #...# #...# ....

洛谷P2699 【数学1】小浩的幂次运算

洛谷P2699 【数学1】小浩的幂次运算 :(这应该是普及题里面很水的存在了)暴力判断, 只不过有个小坑就是当sum*w的时候会溢出(long)的问题。 所以我们要改进一下判断条件,从 sum * w r 变为 sum r/w; import java.util.Scanner;public class Main { publi

DFS洛谷P1605 迷宫

DFS洛谷P1605 迷宫 DFS洛谷P1605 迷宫(我的算法学习之路) 标签:搜索 地推 枚举,暴力 #includeiostream#includestdio.h#includealgorithmusing namespace std;int n,m,t,sx,sy,fx,fy,ans;bool mp[10][10];//用来存放障碍物 bool vis[10][10];int xx[4]={1,

【亡羊补牢】挑战数据结构与算法 第46期 LeetCode 101. 对称二叉

【亡羊补牢】挑战数据结构与算法 第46期 LeetCode 101. 对称二叉树(二叉树) 仰望星空的人,不应该被嘲笑 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \3 4 4 3 但是下面这个 [1,2,2,null,3,null,3]

洛谷p5710答案C语言,洛谷题单 101【入门2】分支结构相关推荐

  1. 【洛谷OJ C++】洛谷题单101 入门2分支结构 题解及学习笔记

    洛谷题单101链接:https://www.luogu.com.cn/training/101#problems 笔记及题解目录: 学习笔记: P5710 [深基3.例2]数的性质 P5711 [深基 ...

  2. 洛谷P2181答案C语言,洛谷P2181 对角线(组合数)

    题目描述 对于一个N个定点的凸多边形,他的任何三条对角线都不会交于一点.请求楚图形中对角线交点的个数. 例如,6边形: 输入输出格式 输入格式: 第一行一个n,代表边数. 输出格式: 第一行输出交点数 ...

  3. 【洛谷OJ C++】洛谷题单100 入门1顺序结构 题解及学习笔记

    洛谷平台题单100链接:https://www.luogu.com.cn/training/100#problems 目录 学习笔记: P1001 A+B Problem P1000 超级玛丽游戏 P ...

  4. 洛谷oj题单【入门2】分支结构-入门难度(Java)

    洛谷oj题单[入门2]分支结构-入门难度(Java) 来源:https://www.luogu.com.cn/training/101#problems P5709 [深基2.习6]Apples Pr ...

  5. c语言程序设计填空带答案,c语言程序设计填空题及答案复习用精编-20210414010859.docx-原创力文档...

    Lele was written in 2021 Lele was written in 2021 C语言程序设计填空题及答案复习用精编 导读:在程序填空题中,已经给出了程序的主干,读者首先要理解程序 ...

  6. 假设当年产值为100c语言答案,C语言程序设计试题题库含答案zdui.doc

    C语言程序设计试题题库含答案zdui 班号姓名 C语言 试 题 题号一二三四五六七八九十总分附加题分数 一.选择题:(20分,每题2分) 1.以下不正确的C语言标识符是( ). A. ABC B. a ...

  7. 假设当年产值为100c语言答案,C语言程序设计试题题库含答案zdui汇总.doc

    C语言程序设计试题题库含答案zdui汇总 班号姓名 C语言 试 题 题号一二三四五六七八九十总分附加题分数 一.选择题:(20分,每题2分) 1.以下不正确的C语言标识符是( ). A. ABC B. ...

  8. 洛谷找最小值c语言,洛谷 P1478 陶陶摘苹果(升级版) C语言实现

    原题地址:P1478 淘淘摘苹果(升级版)- 洛谷 题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他手够不着时,他会站到椅子上再试试. 这次与NO ...

  9. 【洛谷】入门2 分支结构

    原题传送门 点我 P5710 [深基3.例2]数的性质 题目描述 一些数字可能拥有以下的性质: 性质 1:是偶数: 性质 2:大于 4 且不大于 12. 小A 喜欢这两个性质同时成立的数字:Uim 喜 ...

  10. 洛谷入门题单 --【入门1】顺序结构 题解

    - [P1001 A+B Problem] - [P1000 超级玛丽游戏] - [P5703 [深基2.例5]苹果采购] - [P5704 [深基2.例6]字母转换] - [P5705 [深基2.例 ...

最新文章

  1. 已知机器人阿木木_LOL殇之机器人 阿木木皮肤
  2. Hyperledger Besu企业以太坊快速教程
  3. 记 Arthas 实现一次 CPU 排查与代码热更新
  4. 2- 计算机的组成,VMware使用
  5. win10无法装载iso文件_win10镜像文件不能安装怎么办?win10镜像文件无法安装的解决教程...
  6. Linux中的僵尸进程处理
  7. python的第三方库是干什么用的-Python最强大的第三方库,你有必要了解一下!
  8. 是时候了,我们需要前端架构师
  9. 安卓期末大作业(AndroidStudio开发),日记本app,代码注释详细,能正常运行
  10. 树莓派与普通USB摄像头的连接
  11. c语言大作业点歌系统,基于C语言的KTV点歌系统
  12. Java程序设计——实现求几何图形的周长面积
  13. 计算机网络期末复习知识点
  14. 平安居家养老服务上市
  15. 【AD封装】DC电源接口、音频接口(带3D)
  16. 计算机语言与智能家居的关系,来谈谈“智能家居”与“家庭自动化”的区别
  17. 听说你觉得自己上了大学就长大懂事了...
  18. Linux下访问处理器硬件信息原理:图形化工具RWLinux的诞生
  19. vlc activex调用
  20. 接手别人的代码,死的心有吗?

热门文章

  1. 【论文复刻】高技术企业认证政策是否促进了中国创新?(heckman两阶段模型 PSM-DID)论文复现
  2. 巨头特斯拉的进击之路
  3. 根据经纬度查询附近地点
  4. “扣哒杯” AI世青赛公布2021-2022年度全国决赛个人获奖名单
  5. 喝咖啡的好处和坏处好处
  6. 题解 P2253 【好一个一中腰鼓!】
  7. 中国土地市场网数据爬取
  8. Python 毕设精品实战案例——快速索引目录Part2
  9. 服务器的mdf文件怎么打开,在没SQL Server数据库情况下怎么打开.MDF文件?
  10. 绝地求生计算机内存不足怎么解决,绝地求生大逃杀虚拟内存不足怎么解决 虚拟内存设置教程...