《算法通关指南---C++编程篇(1)》
《151道题带你快速梳理C++知识(1)–C++入门》
🔥小龙报:个人主页
🎬作者简介:C++研发,嵌入式,机器人方向学习者
❄️个人专栏:《C语言》《算法》KelpBar海带Linux智慧屏项目
✨永远相信美好的事情即将发生
前言
本专栏聚焦算法题实战,系统讲解算法模块:以《c++编程》,《数据结构和算法》《基础算法》《算法实战》 等几个板块以题带点,讲解思路与代码实现,帮助大家快速提升代码能力
ps:本章节题目分两部分,比较基础笔者只附上代码供大家参考,其他的笔者会附上自己的思考和讲解,希望和大家一起努力见证自己的算法成长
一、Hello,World!
1.1题目链接:Hello,World!
1.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{cout << "Hello,World!" <<endl ;return 0;
}
二、打印飞机
2.1题目链接:打印飞机
2.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{cout << " ** " <<endl;cout << " ** " <<endl;cout << "************" <<endl;cout << "************" <<endl;cout << " * *" <<endl;cout << " * *" <<endl;return 0;
}
三、第二个整数
3.1题目链接:第二个整数
3.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{int a,b,c;cin >> a >> b;cout << b << endl;return 0;
}
四、字符三角形
4.1题目链接:字符三角形
4.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{char x = '0';cin >> x;cout << " " << x << endl;cout << " " << x << x << x << endl;cout << x << x << x << x << x << endl;return 0;
}
五、整数
5.1题目链接:整数
5.2题目解析
六、打印字符
6.1题目链接:打印字符
6.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int b = 0;cin >> b;char ch = b;cout << (char)b << endl;return 0;
}
七、倒序
7.1题目链接:倒序
7.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int a = 0;int b = 0;int c = 0;cin >> a >> b >> c;cout << c << " " << b << " " << a << endl;return 0;
}
八、倒序
8.1题目链接:倒序
8.2题目解析
#include <iostream>
using namespace std;
int main()
{int a = 0;int b = 0;int c = 0;cin >> a >> b >> c;cout << c << " " << b << " " << a << endl;return 0;
}
九、买票
9.1题目链接:买票
9.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int n = 0;short s = 0;cout << sizeof(n) << " " << sizeof(s) << endl;return 0;
}
十、A+B问题
10.1题目链接:A+B
10.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int A = 0;int B = 0;cin >> A >> B;cout << A + B << endl;return 0;
}
十一、鸡兔共笼
11.1题目链接:鸡兔同笼
11.2题目解析
代码;
#include <iostream>
using namespace std;
int main()
{int b = (35 * 4 - 94) / 2;int a = 35 - b;cout << a << " " << b << endl;return 0;
}
十二、计算 (a+b)×c 的值
12.1题目链接:计算 (a+b)×c 的值
12.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{int d = 0;int a,b,c;cin >> a >> b >> c;d = (a + b) * c;cout << d << endl;return 0;
}
十三、带余除法
13.1题目链接:带余除法
13.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{int a,b;cin >> a >> b;cout << a / b << " " << a % b << endl;return 0;
}
十四、整数个位
14.1题目链接:整数个位
14.2题目解析
:
代码:
#include<iostream>
using namespace std;
int main()
{int a = 0;cin >> a;cout << a % 10 << endl;return 0;
}
十五、整数十位
15.1题目链接:整数十位
15.2题目解析
代码:
#include <iostream>
using namespace std;
int a;
int main()
{cin >> a;int b = abs(a);cout << (b / 10) % 10 << endl;return 0;
}
十六、时间转换
16.1题目链接:时间转换
16.2题目解析
代码:
#include <iostream>
using namespace std;int main()
{int seconds = 0;cin >> seconds;cout << seconds / 3600 << " "; //提取小时cout << seconds / 60 % 60 << " "; //提取分钟cout << seconds % 60 << endl; //提取秒return 0;
}
十七、小鱼的游泳时间
17.1题目链接:小鱼的游泳时间
17.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{int a,b,c,d;int e,f;int t = 0;cin >> a >> b >> c >> d;t = c * 60 + d - a * 60 - b; //转化成分钟e = t / 60;f = t % 60;cout << e <<" " << f << endl;return 0;
}
十八、交换值
18.1题目链接:交换值
18.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int a = 0;int b = 0;cin >> a >> b;int c = a; //c是⼀个临时变量,作为中间变量实现交换的 a = b;b = c;cout << a << " " << b << endl;return 0;
}
十九、计算成绩
19.1题目链接:计算成绩
19.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int a,b,c,sum;cin >> a >> b >> c;sum = a * 0.2 + b * 0.3 + c * 0.5;cout << sum << endl;return 0;
}
二十、浮点数向零舍入
20.1题目链接:浮点数向零舍入
20.2题目解析
代码:
#include<iostream>
using namespace std;
int main()
{double x;cin >> x;cout << (long long)x << endl;return 0;
}
二一、打印 ASCII 码
21.1题目链接:打印 ASCII 码
21.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{char ch = '0';cin >> ch;cout << (int)ch << endl;return 0;
}
二二、打印字符
21.1题目链接:打印字符
21.2题目解析
代码:
#include <iostream>
using namespace std;
int main()
{int b = 0;cin >> b;char ch = b;cout << (char)b << endl;return 0;
}