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

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

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

P1046 陶陶摘苹果

990012668b16f9a955fcdab84bcef490.png

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号码

97ef3036de9cec94b130dc226d04c0ad.png

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 不高兴的津津

d83890e74bf0f3d67192d55d525208cd.png

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 小玉家的电费

b93064c130a8bf1d19daa0d92aaf4957.png

#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 小鱼的航程(改进版)

f5be5ed704518eea11ce20709e47e980.png

#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 三角函数

c2d71d02d3994b0d709ddde0f92bcb89.png

题解:

正弦值=直角边/斜边

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

#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 买铅笔

c424ca825a232650ca04e9b964f06e55.png

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

675e88c6e4c8165825cc73fbf4ff9ab6.png

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】数的性质

177fd8fbe327154dff390309a47b03f7.png

#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】闰年判断

1ca73b2305f2662e53d50dab7ded7715.png

#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

71db8a4c5cc237c38f8a92feb3faa840.png

#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】洛谷团队系统

46dabc07bf2ef17a6647f6c091103b62.png

#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】肥胖问题

2e311aa83b67ea6ba60f2ac26b8491e8.png

#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】三位数排序

35b2651cf43a6edecb79bf612ef5a5aa.png

更多方法可点击本处

题解:快排,代码如下:

#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】月份天数

7c4a245a634d0bbd926cdf301251ce8e.png

#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】三角形分类

8831369754da42ab4384e7014a7dfb11.png

#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]

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值