算法-cpp入门语法练习题

发布于:2025-02-10 ⋅ 阅读:(99) ⋅ 点赞:(0)

本期小编给大家带来了最基本的语法练习题.
下面相关习题在B站视频: 链接有讲解.

下面是CPP基本语法练习题: CPP入门习题, 有兴趣可以参考:

1. 简单汇总

题目名称 题目链接 难度 思路 参考代码 备注
打印 “hello world” https://www.luogu.com.cn/problem/B2002 c //题目链接: https://www.luogu.com.cn/problem/B2002#submit //题目: B2002 Hello,World! //代码: #include<iostream> using namespace std; int main() { cout << "Hello,World!" << endl; return 0; }
打印"小飞机" https://ac.nowcoder.com/acm/contest/18839/1003 c //题目链接: https://ac.nowcoder.com/acm/contest/18839/1003 //题目: 小飞机 //代码: #include<iostream> using namespace std; int main() { cout << " ** " << endl; cout << " ** " << endl; cout << "************" << endl; cout << "************" << endl; cout << " * * " << endl; cout << " * * " << endl; return 0; }
输出第二个整数(给你三个整数) https://www.luogu.com.cn/problem/B2003 c //题目链接: https://www.luogu.com.cn/problem/B2003#submit //题目: B2003 输出第二个整数 //代码: #include<iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << b << endl; return 0; }
打印字符三角形 https://www.luogu.com.cn/problem/B2005 cpp //题目链接: https://www.luogu.com.cn/problem/B2005 //题目: B2005 字符三角形 //代码: #include<iostream> using namespace std; int main() { char ch = '0'; cin >> ch; printf(" %c \n", ch); printf(" %c%c%c \n", ch, ch, ch); printf("%c%c%c%c%c\n", ch, ch, ch, ch, ch); return 0; }
接收整数并输出 https://ac.nowcoder.com/acm/problem/21985 cpp #include<iostream> using namespace std; int main() { int num = 0; cin >> num; cout << num << endl; return 0; }
打印字符 https://www.luogu.com.cn/problem/B2018 cpp #include<iostream> using namespace std; int main() { int ch; cin >> ch; cout << (char)ch << endl; return 0; }
倒序(给你三个整数, 倒着输出) https://ac.nowcoder.com/acm/problem/21993 cpp #include<iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << c << " " << b << " " << a; return 0; }
sizeof(int)
sizeof(short)
http://ybt.ssoier.cn:8088/problem_show.php?pid=1016 cpp cout << sizeof(int) << " " << sizeof(short) << endl;
买票(使用*运算符) https://www.nowcoder.com/practice/0ad8f1c0d7b84c6d8c560298f91d5e66 cpp #include <iostream> using namespace std; int main() { int x = 0; cin >> x; cout << x * 100 << endl; } // 64 位输出请用 printf("%lld")
A + B 问题 https://www.luogu.com.cn/problem/B2007 cpp #include<iostream> using namespace std; int main() { int x = 0, y = 0; cin >> x >> y; cout << x + y << endl; return 0; }
鸡兔同笼问题 https://www.luogu.com.cn/problem/B2614 cpp #include<iostream> using std::cout;using std::endl; int main() { int j = 0; int t = 0; int f = 94; int h = 35; j = ((4 * h) - f) / 2; t = h - j; cout << t << " " << j << endl; return 0; }
计算 a+b*c https://www.luogu.com.cn/problem/B2008 cpp #include<iostream> using namespace std; int main() { int a = 0, b = 0, c = 0; cin >> a >> b >> c; cout << (a + b) * c << endl; return 0; }
带余除法 https://www.luogu.com.cn/problem/B2010 cpp #include<iostream> using namespace std; int main() { int a = 0, b = 0; cin >> a >> b; cout << a / b << " " << a % b << endl; return 0; }
整数个位 https://ac.nowcoder.com/acm/problem/21990 cpp #include<iostream> using namespace std; int main() { int n = 0; cin >> n; cout << n % 10 << endl; return 0; }
整数十位 https://ac.nowcoder.com/acm/problem/21991 cpp #include<iostream> using namespace std; int main() { int n = 0; cin >> n; cout << ((n / 10) % 10) << endl; return 0; }
时间转换 https://ac.nowcoder.com/acm/contest/18839/1031 cpp #include<iostream> using namespace std; int main() { int n = 0; cin >> n; int h = n / 60 / 60 % 24; int m = n / 60 % 60; int s = n % 60; cout << h << " " << m << " " << s << endl; return 0; }
小鱼的游泳时间 https://www.luogu.com.cn/problem/P1425 cpp #include<iostream> using namespace std; int main() { int a = 0, b = 0, c = 0, d = 0; cin >> a >> b >> c >> d; int s1 = a * 60 + b; int s2 = c * 60 + d; int ret = s2 - s1; cout << ret / 60 << " " << ret % 60 << endl; return 0; }
交换 a, b 的值 http://ybt.ssoier.cn:8088/problem_show.php?pid=2064 cpp int main() { int a = 10; int b = 20; swap(a, b); }
按权重计算成绩 https://ac.nowcoder.com/acm/contest/18839/1034 cpp #include<iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * 0.2 + b * 0.3 + c * 0.5 << endl; return 0; }
浮点数向零舍入 https://www.luogu.com.cn/problem/B2016 cpp #include<iostream> using namespace std; int main() { double a; cin >> a; cout << (long long)a << endl; return 0; } int范围
打印 ASCII 码 https://www.luogu.com.cn/problem/B2017 cpp #include<iostream> using namespace std; int main() { char ch; cin >> ch; cout << (int)ch << endl; return 0; }
打印字符 https://www.luogu.com.cn/problem/B2018 cpp #include<iostream> using namespace std; int main() { int ch; cin >> ch; cout << (char)ch << endl; return 0; }

因为整体都很简单, 因此只给了链接 和 参考代码, 再不懂可以见视频:
视频链接


EOF.


网站公告

今日签到

点亮在社区的每一天
去签到