/*
gesp2必会代码、编程思想 v1.0.5
zycsuper 2026/5/17
*/

/* 
p:浮点数相等判断
s:相减的绝对值小于0.000001就算相等,不能用==
  例如2.2345676和2.2345677就可以视作相等
  不能用a==b判断
c: 
#include <bits/stdc++.h>
using namespace std;
int main() {
    double a=2.2345676;
    double b=2.2345677;
    if (abs(b-a) <= 0.000001) cout<<"equal";
    else cout<<"not equal";
    return 0;
} */

/*
p:连续输出数,全部右对齐
s:使用setw和right或者printf("%3d")
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
    for (int i=0;i<20;i++) {
        if (i%3==0) cout<<endl;
           cout << setw(3) << right << i;  //右对齐,占3位
           //printf("%3d",i);                  //等效
    }
} */

/*
p:连续输出数,全部左对齐
s:使用cout<<left<<setw(5)或者 printf("%-5d%"),其中后者的“-”表示左对齐
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int g=5,m=23,x=567;
    //cout<<left<<setw(5)<<g<<setw(5)<<m<<setw(5)<<x<<endl;    //左对齐
    //cout<<left<<setw(5)<<532<<setw(5)<<76<<setw(5)<<9<<endl;
    printf("%-5d%-5d%-5d\n", 532, 76, 9);                    //等效
    return 0;
} */

/* 2026/3/15
p:连续输出数,不足处前面补0
s:使用printf("%03d ",i);
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int g=5;
    printf("%03d ",g);                //每位宽度3,不足3位,前面补0
    return 0;
} */


/*
p:数字反转
s:数字累加法(不用字符串)
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    x=12345;
    int r=0;
    while (x != 0) {
        int d = x % 10;
        x /= 10;
        r = r * 10 + d;
    }
    cout<<r;
    return 0;
}*/

/*
p:过了n天是星期几?(含当前天)
s:(x+n)%7,或者(x+n-1)%7+1,其中x是当前星期数 小杨的考试
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x=6;   //星期天,0;其余用数字
    int n=9;
    cout<<(x+n-1)%7+1;
    return 0;
}*/

/*
p:判断质数
s:枚举判断法
c:
bool isPrime(int n) {
    if (n<2) return false;
    for (int i=2;i<=sqrt(n);i++) {
        if (n%i==0) return false;
    }
    return true;
} */

/*
p:一直前面多个变量值,求后面变量值
s:迭代递推,例如:小杨做题
c:
#include <iostream>
using namespace std;
int main() {
    int a,b;
	int m,n;
	cin>>a>>b>>m>>n;  
	int c;        //新的一天做的题
	int sum=a+b;  //累加初始值不是0了,因为前两天做了题
	for (int i=3;i<=n;i++) {
		c=a+b;
		sum+=c;
		a=b;      //b相当于原来的第1天    
		b=c;      //c相当于原来的第2天
		if (c>=m) break;
	}
	cout<<sum; 
	return 0;
} */

/*2026/1/31
p:数根问题:数位分离求和,直到剩下最后1位数,比如678
  6+7+8=21
  2+1=3
  数根是3
s:方法一:数位分离,求和。然后和继续如前操作,直到和是单个数字,就是数根
c:
#include <bits/stdc++.h>  //数根问题:方法一
using namespace std;
int main() {
    unsigned long long n;
    cin >> n;                   //输入数字 
    if (n == 0) {
    	cout<<0;
	    return 0;               //0的树根就是0 
	}
    unsigned long long r = n;   //最大正整数 
    while (r >= 10) {           // 只要和不是一位数,就继续相加
        int t = 0;              // 每次累加 
        while (r > 0) {   //数位分离 
            t += r % 10;  //取最后一位 t=t+r%10 
            r /= 10;      //去掉最后一位 t=t/10
        }
        r = t;            //更新总和 
    }
    cout << r << endl;
    return 0;
}*/

/*2026/1/31
p:数根问题:数位分离求和,直到剩下最后1位数,比如678
  6+7+8=21
  2+1=3
  数根是3
s:方法二:直接求余数,最简单
c:
#include <bits/stdc++.h>  //数根问题:方法二
using namespace std;
int main() {
    unsigned long long n;
    cin >> n;                   //输入数字 
    cout<<n%9; 
    return 0;
}*/

/*2026/5/17
p:随机数
s:利用srand,rand
c:
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x;
	srand(time(0));  //随机基准 
	
	//1~N之间的随机数
//	const int N=10;
//	x=rand()%N+1; 
//	cout<<x;

    //M~N之间的随机整数
    const int M=100;
    const int N=200;
	x=rand()%(N-M+1)+M;
	cout<<x;
} */

/*
编程思想:计算思维
1、图形输出方法:列表分析法:典型例题:菱形
2、图形输出方法:特殊值判定法:典型例题:小杨的H字矩阵
4、嵌套循环:外层循环套内层循环,相当于双重枚举
5、分类讨论:例如:时间跨越。当问题复杂时,分成多个种类
6、递推思想:根据前面的值计算后面的值,反复迭代
*/