C/C++
孤舟独钓寒江雪
这个作者很懒,什么都没留下…
展开
-
C++ 对txt文件的读写
#include <iostream>#include <string>#include <fstream>#include <vector>#include <algorithm>using namespace std;void Trim(string &str){ // 去掉字符串首尾的特殊字符 \f:换页 \v:垂直制表 \r:回车 \t:水平制表 \n:换行 string blanks("\f\v\r\t\n.原创 2022-03-31 00:09:19 · 1987 阅读 · 0 评论 -
C/C++知识点
友元函数在定义一个类的时候,可以把一些函数(全局函数和其他类的成员函数)声明为友元,这些函数就成为该类的友元函数,在友元函数内部就可以访问该类对象的私有成员。将全局函数声明为友元:friend 返回值类型 函数名(参数列表);将其他类的成员函数(不是私有成员函数)声明为友元:friend 返回值类型 其他类的类名::成员函数名(参数列表);友元类一个类A可以将另一个类B声明为自己的友元,类B的所有成员函数就都可以访问类A对象的私有成员。在类定义中声明友元类:friend class 类名;原创 2022-03-27 22:25:20 · 877 阅读 · 0 评论 -
常用小程序
最大公约数,最小公倍数#include <iostream>using namespace std;/*A,B的最小公倍数=A*B/A,B的最大公约数 *求最大公约数---碾转相除法:转换为A,B相除的余数与A,B间较小数的最大公约数*/int gcd(int a, int b){ int temp = 0; while (temp = a%b) { a = b; b = temp; } return b;}int main(){ int a, b;原创 2021-03-16 10:19:57 · 93 阅读 · 0 评论 -
2021-03-04
#include<stdio.h>#include<string.h>#include<stdlib.h>//judge legal charint isLegal(char a) { if (a >= 'a' && a <= 'z') { return 1; } if (a >= 'A' && a <= 'Z') { return 1; ..原创 2021-03-04 13:49:07 · 119 阅读 · 1 评论 -
八皇后问题
#include <iostream>using namespace std;const int N = 8;int total_cnt, arr[10];//arr:记录每一行(X)皇后的Y列//全局遍历:默认total_cnt=0;bool isPlaceOK(int *a, int n, int c) {//n行c列 for (int i = 1; i <= n - 1; ++i) { if (a[i] == c || a[i] - i == c原创 2021-03-11 08:50:56 · 55 阅读 · 0 评论 -
复试
2019第一场 最长连续合数段#include<stdio.h>#include<string.h>int isHeshu(int n){ for(int i=2;i*i<=n;i++) if(n%i==0) return 1; return 0;}int main(){ int n,m,max_count=0,max_id=0,count=0,id=0,flag=0; sca原创 2021-03-03 09:36:19 · 94 阅读 · 0 评论 -
C/C++ 常用缩写词
addition addanswer ansarray arraverage avgbuffer buf或buffcapture cap或captcheck chkcount cntcolumn colcontrol ctrldecode decdefine defdelete deldestination dst或destdisplay dispdivision diven原创 2021-02-10 18:25:09 · 1145 阅读 · 0 评论 -
C++ I/O流
C++ I/Ocin的基本用法结束条件:[enter],[space],[tab]处理方法:cin遇到缓冲区中的[enter],[space],[tab]会结束当前输入,并舍弃[enter],[space],[tab],继续下一项输入,当有连续[space],[enter,[tab]会全部舍弃。#include<iostream>using namespace std; int main(){ char a[10],b[10]; cin>>a;c原创 2021-02-09 16:04:38 · 85 阅读 · 0 评论