c++ 编程题目
c++ 实战编程题目
啥都亿点点的研究生
这个作者很懒,什么都没留下…
展开
-
给定一个仅包含小写字母的字符串,求它的最长回文子串的长度。
#include<iostream>#include<set>#include<algorithm>using namespace std;void printset(set<int>& s){ set<int>::iterator it = s.end(); it--; cout << *it << endl;}int main(){ string a; cin >> a原创 2021-05-08 09:12:49 · 1604 阅读 · 0 评论 -
接受一个只包含小写字母的字符串,然后输出该字符串反转后的字符串。(字符串长度不超过1000)
#include<iostream>#include<vector>#include<algorithm>using namespace std;void printvector(vector<char>& v){ for (vector<char>::iterator it = v.begin(); it != v.end(); it++) { cout << *it ; }}int main()原创 2021-05-08 07:16:15 · 1230 阅读 · 0 评论 -
找出给定字符串中大写字符(即‘A‘-‘Z‘)的个数。
#include<iostream>#include<string>#include<list>using namespace std;int printlist(list<int>& lst){ int num = 0; for (list<int>::iterator it = lst.begin(); it != lst.end(); it++) { if (*it >= 65 && *it原创 2021-05-07 20:45:40 · 654 阅读 · 0 评论 -
功能:等差数列 2,5,8,11,14。。。。 输入:正整数N >0 输出:求等差数列前N项和 本题为多组输入,请使用while(cin>>)等形式读取数据
#include<iostream>#include<list>#include<numeric>using namespace std;int printlist(list<int>& lst){ int value; value=accumulate(lst.begin(), lst.end(), 0); return value;}int main(){ list<int>lst; int a = 2;原创 2021-05-07 20:15:25 · 411 阅读 · 0 评论 -
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
#include<iostream>#include<string>#include<list>using namespace std;void printlist(list<char>& lst){ lst.reverse(); for (list<char>::iterator it=lst.begin();it!=lst.end();it++) { cout << *it ; }}in原创 2021-05-07 19:51:17 · 911 阅读 · 0 评论 -
输入一个整数,将这个整数以字符串的形式逆序输出 程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001
#include<iostream>#include<list>using namespace std;void printlist(list<char>& lst){ lst.reverse(); for (list<char>::iterator it=lst.begin();it!=lst.end();it++) { cout << *it ; }}int main(){ string a ;原创 2021-05-07 19:45:35 · 690 阅读 · 0 评论 -
输入一个int型的正整数,计算出该int型数据在内存中存储时1的个数。
#include<iostream>using namespace std;int main(){ int input; cin>>input; int count =1; while (input!=1) { if (input % 2 == 1) { count++; } input = input / 2; } cout << count << endl; return 0;}```原创 2021-05-06 20:25:41 · 242 阅读 · 0 评论 -
写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。
#include<iostream>using namespace std;int Myint(float m){ int n = m * 10; int temp = n % 10; int fina; if (temp < 5) { fina = int(m); } else { fina = int(m) + 1; } return fina;}int m原创 2021-05-06 16:58:43 · 874 阅读 · 0 评论 -
c++ 对随机数组进行去重和排序输出
#include <string>#include<iostream>#include <algorithm>void test3(){ /*明明想在学校中请一些同学一起做一项问卷调查, 为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000), 对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。 然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重” 与“排序”的工原创 2020-12-28 22:27:30 · 1059 阅读 · 0 评论 -
c++ 写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字母, 然后输出输入字符串中该字母的出现次数。不区分大小写。
include<iostrem>include<string>using namespace std;void test2(){ /*写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字母, 然后输出输入字符串中该字母的出现次数。不区分大小写。 示例:ABCabc 待统计字符:A */ cout << "请输入一串由字母、数字和空格组成的字符串:" << endl; string arr; getline(cin, arr);原创 2020-12-27 21:23:51 · 3254 阅读 · 2 评论 -
c++ 输入字符串,最后输入字符串最后一个单词的长度。
//计算字符串最后一个单词的长度,单词以空格隔开。//输入一行,代表要计算的字符串,非空,长度小于5000。//输出一个整数,表示输入字符串最后一个单词的长度。//输入:hello nowcoder 输出:8#include <string>#include<iostream>using namespace std;void test1(){ cout << "请输入一行字符串:(按回车结束输入)" << endl; string arr原创 2020-12-27 20:58:53 · 410 阅读 · 0 评论