算法-cpp入门语法练习题

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

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

1. 简单汇总

题目名称题目链接难度思路参考代码备注
打印 “hello world”https://www.luogu.com.cn/problem/B2002c //题目链接: 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/1003c //题目链接: 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/B2003c //题目链接: 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/B2005cpp //题目链接: 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/21985cpp #include<iostream> using namespace std; int main() { int num = 0; cin >> num; cout << num << endl; return 0; }
打印字符https://www.luogu.com.cn/problem/B2018cpp #include<iostream> using namespace std; int main() { int ch; cin >> ch; cout << (char)ch << endl; return 0; }
倒序(给你三个整数, 倒着输出)https://ac.nowcoder.com/acm/problem/21993cpp #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=1016cpp cout << sizeof(int) << " " << sizeof(short) << endl;
买票(使用*运算符)https://www.nowcoder.com/practice/0ad8f1c0d7b84c6d8c560298f91d5e66cpp #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/B2007cpp #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/B2614cpp #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*chttps://www.luogu.com.cn/problem/B2008cpp #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/B2010cpp #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/21990cpp #include<iostream> using namespace std; int main() { int n = 0; cin >> n; cout << n % 10 << endl; return 0; }
整数十位https://ac.nowcoder.com/acm/problem/21991cpp #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/1031cpp #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/P1425cpp #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=2064cpp int main() { int a = 10; int b = 20; swap(a, b); }
按权重计算成绩https://ac.nowcoder.com/acm/contest/18839/1034cpp #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/B2016cpp #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/B2017cpp #include<iostream> using namespace std; int main() { char ch; cin >> ch; cout << (int)ch << endl; return 0; }
打印字符https://www.luogu.com.cn/problem/B2018cpp #include<iostream> using namespace std; int main() { int ch; cin >> ch; cout << (char)ch << endl; return 0; }

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


EOF.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值