- 博客(21)
- 收藏
- 关注
原创 结构体的简单使用(冒泡排序学生成绩)
#includeusing namespace std;struct stu{char name[21];float scores[3];};int main(){struct stu s[3];for(int i=0;i<3;i++){cout<<“请输入学生的姓名 成绩:”<<endl;cin>>s[i].name>&g...
2018-10-29 16:40:39
2150
原创 指针函数之实现strcat函数
#define _CRT_SECURE_NO_WARNINGS#pragma warning(disable:4996)using namespace std;char * mystrcat(char *dest, char *src){char *origin = NULL;origin = dest;//保存最初的位置while (*dest)dest++;while (...
2018-10-18 19:55:40
1435
原创 自定义strstr函数(指针)
#include#include&lt;string.h&gt;using namespace std;char * mystrstr(char *arr1,char *arr2){char *g=NULL;int i=0;int j=0;int count=0;int len=strlen(arr2);while(arr1[i]!=’\0’){g=&amp;arr1[i]...
2018-10-17 17:51:08
542
原创 (指针函数)自定义char指针strchr函数
#define _CRT_SECURE_NO_WARNINGS//查找字符串s中首次出现字符c的位置,返回首次出现c的位置的指针,如果s中不存在c则返回NULL#include"stdafx.h"#include#include<string.h>#include<stdlib.h>using namespace std;//char * mystrchr(c...
2018-10-13 22:14:22
837
原创 c++自己定义比较字符串大小的函数
#include “stdafx.h”#includeusing namespace std;int my_strcmp(char s1[], char s2[]);int main(){char s1[] = “hello world”;char s2[] = “hello abc”;int flag = my_strcmp(s1, s2);if (flag == 0){/...
2018-10-09 21:19:21
3529
原创 用函数实现冒泡算法
#include “stdafx.h”#includeusing namespace std;void maopao(int arr[], int n);int main(){int arr[] = {1,5,7,4,9,3,2};int n = sizeof(arr) / sizeof(int);maopao(arr, n); for (int i = 0; i &lt; n;...
2018-10-08 20:11:30
875
转载 c++中字符串的比较(string头文件和compare函数的使用)
#include “stdafx.h”#include#includeusing namespace std;int main(){string a, b;cin &gt;&gt; a;cin &gt;&gt; b;if (a.compare(b) &gt; 0){cout &lt;&lt; “a&gt;b”&lt;&lt;en
2018-10-08 19:28:11
6081
1
转载 c++读取带空格字符串
关于在C++中字符串的输入整理笔记cincin是C++中最常用的输入语句,当遇到空格或者回车键即停止如:#include #include using namespace std;int main(){chara[50];cin&gt;&gt;a;cout&lt;&lt;a&lt;&lt;endl;return0;}输入:abcd遇回车输出abcd缺点:只能输入没有...
2018-10-08 19:27:55
3196
原创 双色球(如何获得随机数以及去重和排序)
//打印双色球 红球6个 +蓝球1个 红球范围1-33,蓝球范围1-11#include “stdafx.h”#include#include&lt;time.h&gt;using namespace std;int main(){srand((unsigned) time(NULL));//生成随机数种子,使得每一次调用rand函数都生成新的数字int ball[8];for...
2018-09-29 22:08:19
4961
原创 二维数组求每名学生的总成绩和平均成绩(c++中字符串的输出)
#include “stdafx.h”#include#include //可以输出字符串using namespace std;int main(){int scores[3][4];cout << “请输入同学姓名以及成绩!”<<endl;for (int i =0; i ❤️; i++){for (int j = 0; j < 4; j++...
2018-09-26 21:59:43
5247
1
原创 两数之和(LEETCODE)
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1]下面是代码:#include “stdafx.h”#includeusing namespace...
2018-09-26 14:52:19
106
原创 冒泡排序
**//冒泡排序:n个数两两比较n-1次,这个过程一共重复n-1次所以用双重循环#include “stdafx.h”#includeusing namespace std;int main(){int args[10] = {5,4,3,2,1,6,8,9,10,12};for (int i = 0; i &amp;amp;lt; 9; i++){for (int j = 0; j &amp;amp;lt; ...
2018-09-25 20:14:59
164
原创 数组逆置
#include “stdafx.h”#includeusing namespace std;int main(){int pigs[10], t;for (int i = 0; i < 10; i++){cin >> pigs[i];}for (int i = 0; i < 10; i++){if (9 - i < i){break;}...
2018-09-25 19:48:48
265
1
原创 找到数组中的最大值以及他的下标
#include “stdafx.h”#includeint max(int pigs[], int n);using namespace std;int main(){int pigs[10];for (int i = 0; i < 10; i++){cin >> pigs[i];}max(pigs, 10);return 0;}int max(in...
2018-09-25 19:28:12
2327
原创 c++正三角形
#include “stdafx.h”#includeusing namespace std;int main(){int n = 0;for (int x = 5; x > 0; x–) {for (int i = 0; i <= x; i++){cout << " ";}for (int y = 0; y < 2 * n + 1; y++)...
2018-09-20 21:51:50
1296
原创 c++倒三角形
#include “stdafx.h”#includeusing namespace std;int main(){int n = 5;for (int x = 0; x < 5; x++) {for (int i = 0; i <= x; i++){cout << " ";}for (int y = 0; y < 2 * n - 1; y++)...
2018-09-20 21:47:46
2515
原创 c++输入n个数,求最大值和最小值
#include “stdafx.h”#includeusing namespace std;int main(){int n,min,max,k;cin >> n;cout << “输入” << n << “个数,求最大值和最小值” << endl;cin >> k;max = min = k;for (...
2018-09-20 18:26:16
37346
4
原创 c++输入8个数取最大值和最小值(定义2个函数)
#include “stdafx.h”#includeusing namespace std;int main(){int m, n,y;for (m = 1; m &lt;= 9; m++) {for (n = 1; n &lt;= m; n++){y = mn;cout &lt;&lt; m &lt;&lt; "" &lt;&am
2018-09-19 23:02:20
3464
原创 c++水仙花数(二)
#include “stdafx.h”#includeint lifang(int);using namespace std;int main(){int i;while (1 == 1) {cin >> i;if (i >= 100 && i <= 1000){if (lifang(i / 100) + lifang(i % 10) ...
2018-09-18 21:57:44
543
原创 c++水仙花数
#include “stdafx.h”#include int lifang(int);using namespace std;int main(){int i;for (i= 100;i<= 999;i++){if (lifang(i / 100) + lifang(i % 10) + lifang(i % 100 / 10) == i)cout << i ...
2018-09-18 21:50:59
743
原创 c++第一次作业(自己定义函数)
includedouble jl(double); int main() { using namespace std; double x; cin &gt;&gt; x; cout &lt;&lt; x &lt;&lt; “long等于:” &lt;&lt; jl(x) &lt;&lt; “码”&
2018-09-15 14:06:17
684
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人