首页
题库
公司真题
专项练习
面试题库
在线编程
面试
面试经验
AI 模拟面试
简历
求职
学习
课程
专栏·文章
竞赛
搜索
我要招人
发布职位
发布职位、邀约牛人
更多企业解决方案
在线笔面试、雇主品牌宣传
登录
/
注册
萌新fighting
获赞
166
粉丝
3
关注
3
看过 TA
18
厦门大学
2016
C++
IP属地:福建
暂未填写个人简介
私信
关注
拉黑
举报
举报
确定要拉黑萌新fighting吗?
发布(11)
刷题
萌新fighting
2021-01-22 15:43
已编辑
C++
字符串分隔(C++)
思路1: 先对不为8的倍数的字符串结尾补0,使其刚好为8的倍数。然后每隔8个字符输出并打印换行符。 代码: #include <iostream> #include <string> using namespace std; int main() { string str; while (cin >> str) { // 补0 int len = str.size(); if (len % 8 != 0) { int count = 8 - le...
0
点赞
评论
收藏
转发
萌新fighting
2021-01-21 20:52
C++
明明的随机数(C++)
思路: 排序、去重,很容易联想到容器set的性质。 代码: #include <iostream> #include <set> int main() { int n; while (std::cin >> n) { std::set<int> stat; int tmp; for (int i = 0; i < n; ++i) { std::cin >> tmp; stat.insert(t...
0
点赞
评论
收藏
转发
萌新fighting
2021-01-21 03:07
C++
计算某字符出现的个数(C++)
思路: 遍历字符串中每一个字符,将每个字符转换为小写与转换为小写的目标字符进行相等比较。也可以转换为大写,只要确保和目标字符使用相同的转换就可以。注意获取的输入如果包含空格需要使用getline()函数获取输入。 代码: #include <iostream> #include <string> int main() { std::string str; getline(std::cin, str); char target; std::cin >> target; int targetCharNum = 0; ...
0
点赞
评论
收藏
转发
萌新fighting
2021-01-21 02:50
C++
字符串最后一个单词的长度(C++)
思路: 从字符串的最后一个字符开始往前遍历,统计字符个数直到遇到空格为止。注意当输入包含空格时需要使用getline()函数获取输入。 代码: #include <iostream> #include <string> int main() { std::string str; getline(std::cin, str); int lastWordLen = 0; int len = str.size(); for (int i = len - 1; i >= 0 && !isspace(str[i])...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-09 14:00
已编辑
C++
超半的数
这题是leetcode原题:https://leetcode-cn.com/problems/majority-element/ 比较令人印象深刻的是官方题解的投票算法,具体解释大家可以去看看,很巧妙的一个方法。 方法五:Boyer-Moore 投票算法 class Solution { public: int majorityElement(vector<int>& nums) { int candidate = -1; int count = 0; for (int num : nums)...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-08 16:36
C++
素数判断
在这个网站有优化后的高效判断素数的方法:https://www.geeksforgeeks.org/primality-test-set-1-introduction-and-school-method/ 下面是我复制过来的,大家可以学一学那个高效的方法,真的厉害。👍 School Method A simple solution is to iterate through all numbers from 2 to n-1 and for every number check if it divides n. If we find any number that ...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-07 22:51
已编辑
C++
一大一小
这题有问题啊。 题目描述是将大的数放在X中,小的数放在Y中。也就是说如果X>=Y那不用交换就可以了。但是我看大家的提交,交换和不交换都能通过。
0
点赞
评论
收藏
转发
萌新fighting
2020-07-07 22:01
C++
温度转换 C++实现
#include <iostream> using namespace std; int main(void) { double f; cin >> f; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); cout << (f - 32) * 5 / 9 << endl; return 0; } 只要确保表达式的第一个数是浮点数,表达式后面的数都会默认转换为浮点数在进行运算。 所以我们只要稍微调...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-07 21:54
C++
平方根 C++实现
贴一个不使用库函数sqrt实现的代码。 #include <iostream> using namespace std; int sqrt(int num); int main(void) { int n; cin >> n; cout << sqrt(n) << endl; return 0; } int sqrt(int num) { for (int i = 0; i * i <= num; ++i) { if ((i + 1) * (i + 1) > n...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-07 21:33
C++
上下取整 C++实现
2种方法:1、使用库函数。2、自己实现相应函数。 贴一个自己的实现: #include <iostream> using namespace std; int roundingDown(double num); int roundingUp(double num); int main(void) { double a; cin >> a; cout << roundingDown(a) << endl; cout << roundingUp(a) << endl; re...
0
点赞
评论
收藏
转发
萌新fighting
2020-07-07 20:49
已编辑
C++
数字反转之-三位数
#include <iostream> using namespace std; int main(void) { int n; cin >> n; while (n != 0) { cout << n % 10; n /= 10; } return 0; } 吐槽下,输出为正整数021,正整数不应该是21吗。。。。。 如果为正整数21,我会这么写: #include <iostream> using namespace std; int ...
0
点赞
评论
收藏
转发
1
工具箱
TA的圈子
暂未加入圈子
TA的圈子
TA的笔记
暂无笔记
TA的笔记
登录
0
天
已登录
0
天
连续登录
0
人
今日访客
牛客网
牛客企业服务