分类: C++

  • #C++ Day7 October 13 2025

    //5 – 6 – 1 bitwise AND operator

    #include <iostream>

    using namespace std;

    /*

    & if there has one 0, there must be 0

    && if there has one false, there must be false

    */

    int main() {

    //1.bitwise AND operator’s definition

    int a = 0b1010; //10

    //0b is mean that binary

    int b = 0b0110; //6

    //   0010      

    cout << (a & b) << endl;//2

    cout << “————-” << endl;

    //2.Parity odd number and even number

    cout << (5 % 2) << endl; // we can know this 5 is also an odd number by moding 2;

    //this kind of manipulator’s priority is high and the efficiency is high too

    cout << (5 & 1) << endl;//we can know this 5 is also an odd number by bitwising AND  1

    //this kind of manipulator’s priority is lower than the mod manipulate,but the  efficiency is the same as bitwise AND manipulator

    //0b101

    //0b001

    //On the binary, if the last bit have the odd number,the whole value must be the odd number

    cout << “————-” << endl;

    //3.retrive the last 5 bits of a number

    int c = 0b1010010101001;

    cout << (c & 0b11111) << endl; // the last 5 bits set binary’s 11111

    cout << “————-” << endl;

    //4.let the last 5 bits into the zero

    int d = 0b11111111111111111111111111100000;

    cout << (c & d) << endl; //  the output must be 0b1010010100000, which is the last 5 bits of c turned into 0,the dec is 5280

    cout << “————-” << endl;

    //5.clean the last continuous 1 on the latter bits

    int e = 0b101010111111;

    //e+1 = 0b101011000000

    // &  = 0b101010000000

    //0b101010000000

    cout << (e & (e + 1)) << endl;

    cout << “————-” << endl;

    //6.to judge the power(幂) of 2 

    int f = 0b100000000;

    //f-1=  0b011111111

    // & =  0b000000000 = 0

    //((f>0)&&( f & (f-1))==0;if equal to 0,the f value must be the power of 2

    cout << (f-1) << endl;

    cout << (f & (f – 1)) << endl;

    return 0;

    }

    //5 – 6 – 2 bitwise OR operator

    #include <iostream>

    using namespace std;

    /*

     | if there has one 1, there must be 1

     || if there has one true, there must true

    */

    int main() {

    //1.the definition of bitwise OR

    int a = 0b1010; //10

    int b = 0b0110; //6

    //  | = 0b1110; // 14

    cout << (a | b) << endl;

    cout << “———” << endl;

    //2.set the flag bit(标记位)

    int c = 0b100111; // 39

    // 0b101111  // 47

    cout << (c | (0b1000)) << endl;

    cout << “———” << endl;

    //3.unset the flag bit

    //0b100111 ->0b100110

    int d = 0b000001;

    // use or operator,and let the last bit become 1 ,then minus the last 1, the operator is adapt to all the number included the last bit has 1 or not has 1

    cout << ((c | d) – d) << endl;

    cout << “———” << endl;

    //4.let last continuous bits’ 0 turned into  1

    int e = 0b1010010000;

    //e-1 = 0b1010001111;

    // & -> 0b1010011111;

    int f = 0b1010011111;

    //  0b1010010000 ->  0b1010011111;

    cout << f << endl;

    cout << (e | (e – 1)) << endl;

    return 0;

    }

  • #C++ Day6 October 12 2025

    //5-3 compare symbol

    #include <iostream>

    using namespace std;

    //== equal

    //!= unequal

    //>  bigger than

    //<  smaller than

    //>= bigger than or equal to

    //<= smaller than or equal to

    int main() {

    int a = 6;

    int b = 9;

    cout << (a == b) << endl; //because << ‘s level is much higher than ==, so we must add () to solve the problem

    cout << (a != b) << endl;

    cout << (a > b) << endl;

    cout << (a < b) << endl;

    cout << (a >= b) << endl;

    cout << (a <= b) << endl;

    return 0;

    }

    //5 – 4 logic symbol

    #include <iostream>

    using namespace std;

    //&& and

    //|| or

    //!  not

    //the priority : ||<&&<!

    // one number symbol’s class is the highest

    //if you don’t know the class, you can add some ()  into it 

    int main() {

    //two values has 2^2 kinds of outcomes

    //1. && and calculate: if have false, there must false

    cout << (0 && 0) << endl;

    cout << (0 && 1) << endl;

    cout << (1 && 0) << endl;

    cout << (1 && 1) << endl; //when all the maniplate numbers are true, the outcome must true, otherwise the outcome is false

    cout << (0 && 0) << endl;

    cout << (0 && 2) << endl;

    cout << (2 && 0) << endl;

    cout << (2 && 2) << endl;//when all the maniplate numbers are true, the outcome must true, otherwise the outcome is false

    // 2 or more the same as 1, because of the algorithm only care about the number is 1 or not 1

    cout << “———” << endl;

    //2.|| or calculate:where there have one true, there must true

    cout << (0 || 0) << endl;

    cout << (0 || 2) << endl;

    cout << (2 || 0) << endl;

    cout << (2 || 2) << endl;// this wave line inform me there is only need one true before the ||  

    cout << “———” << endl;

    //3. ! not calculate:not true is false, not false is true

    cout <<  !0 << endl;

    cout << !2 << endl;

    cout << “———” << endl;

    int a = !((5 > 4) && (7 – 8) && (0 – 1));

    cout << a << endl;

    int b = !(1 || 1 && 0); // the && and symbol’s class is higher than the || or maniplate symbol

    cout << b << endl;

    return 0;

    }

    //5 – 5, comma symbol

    #include <iostream>

    using namespace std;

    int main() {

    int a = 1;//must has an origin value

    //a = 5 – 6, 8 + 9, 100 / 7;//the , comma ‘s priority is really low, lower than the = ,so we must add () into it

    a = (5 – 6, 8 + 9, 100 / 7);//the , comma ‘s priority is really low, lower than the = ,so we must add () into it

    //-1 ,17 ,14

    //the comma symbol will output the last value

    cout << a << endl;

    //example 1:

    int x = 4;

    int y = 5;

    cout << x << ” ” << y << endl;

    int temp = x;

    x = y;

    y = temp;

    cout << x << ” ” << y << endl;

    //we can use it in a loop,which can easily change the value 

    temp = x, x = y, y = temp;

    cout << x << ” ” << y << endl;

    return 0;

    }

  • #C++ Day5 October 11 2025


    //5-1-1 math symbols


    #include <iostream>


    using namespace std;



    int main() {


    int a = 1;


    int b = 3;


    cout << a+b << endl;


    cout << a – b << endl;


    cout << a * b << endl;


    cout << a / b << endl; //if int divide int, there will be int too


    cout << a*1.0 / b << endl;//if int multiple float before divide, there will be float



    a = 10000000;


    b = 100000;


    cout << a * b << endl; //output will out the range of int


    cout << (long long)a * b << endl; //we can translate it forcely



    a = -1;


    b = 2;


    cout << a / b << endl;//just cut of the dot number



    a = +1;


    b = -a;


    int c = -(-a);


    cout << a <<‘ ‘ << b <<‘ ‘ << c << endl;//postive & negative



    char A = ‘A’;


    A = A + 1;


    A = A + 24;



    cout << A << endl;



    return 0;


    }




    //5-1-2 mod % symbol


    #include <iostream>


    using namespace std;



    int main(){


    int a = 100;


    int b = 9;


    cout << a % b << endl; //1



    a = 100;


    b = -9;


    cout << a % b << endl; //1



    a = -100;


    b = 9;


    cout << a % b << endl;//the mod symbol %;-100 % 9 is  9*-11 (near 0 direction) not -12 in C/C++ launguage


    //-1





    a = -100;


    b = -9;


    cout << a % b << endl; //-100 -(-9)*11=-1


    //-1



    //1、the symbol of mod is the same as the be devided number


    //first we should take the negative symbol from the  be devided number 


    //second we use it as 100 = -9 * (-11) + 1 


    //third the left +1 is the lease number and add the negative symbol – to the 1


    //fourth the final answer is  -1


    return 0;


    }




    //5 – 1-3 ++ & –symbol


    #include <iostream>


    using namespace std;



    int main() {


    int a = 6; 


    a++; //a=a+1


    cout << a << endl;


    ++a; //a=a+1


    cout << a << endl;


    //the same in the two ways



    int j = 8;


    int x = a++; //first give the value to x, then add 1 to a


    int y = ++j; //first add 1 to the value , then give the value to y (this type is more effective)


    cout << x << endl; 


    cout << y << endl;



    int z = (a++) + (++a);//9+11=20 we must not to write this type code ,because it will make a big problem


    cout << z << endl;



    a–; //a=a-1


    cout << a << endl;


    –a;//a=a-1


    cout << a << endl; 


    }



    //5 – 2 valued symbols


    #include <iostream>


    using namespace std;



    int main() {


    int x = 9;


    int y = 6;


    x = y; // let y to x


    cout << x << endl;



    x += y; //x=x+y   the length is 10 bytes to 7 bytes


    cout << x << endl;



    x -= y; //x=x-y


    cout << x << endl;



    x *= y; //x=x*y


    cout << x << endl;



    x /= y; //x=x/y


    cout << x << endl;



    x %= y; //x=x%y


    cout << x << endl;


    return 0;


    }






  • #C++ Day4 Sep 14 2025

    #include <iostream>

    using namespace std;

    int main() {

    char a = ‘y’; //use the single quotes can be recognized the char type

    char b = ‘z’;

    //char a =”y”;//using double quotes can be recognized as a lot of string

    cout << a << endl;

    cout << int(a) << endl; //cause 1 byte can be 1*2^8=256 ,so that can be include ascii symbol

    //cout << b – a << endl;

    b = 121;

    cout << b << endl;

    cout << sizeof(a) << endl;

    cout << sizeof(char) << endl;

    return 0;

    }

    Day4 October 10 2025

    //4-5 translate words

    #include <iostream>

    using namespace std;

    int main() {

    char a = ‘\a’;

    char n = ‘\n’; //ascii = 7 , which is \a and would make a beep sound

    cout << int(a) << endl;

    cout << “Vito \”Al\”\\gorith\088m Union\tV\0ito” << n; // \n as a key words change the line;\t is tab ;\\can output a \;\0 will cut out;

    //\” can output the ” normally

    return 0;

    }

    /*

    \0xx is a octal(8 position rule)

    \088 would not recognized a real function

    \077 is a ? symbol

    */

    //4-6 string

    #include <iostream>

    #include <string>

    using namespace std;

    int main() {

    char a[] = “维克托算法联盟”; //the end of the string will be a ‘\0’, which made it as the string for the system recognizing 

    //the GBK UTF-8 can change the encode ways 

    //this is the C style string

    cout << sizeof(a) << endl;

    cout << a << endl;

    string b = “夜深人静看算法”;//this is C++ style string 

    cout << b +”vito” << endl; // import the string class can add another string easily 

    return 0;

    }

    //4-7 type bool

    #include <iostream>

    using namespace std;

    // bool is true or flase

    int main() {

    bool flag1 = false;

    bool flag2 = true;

    cout << flag1 << endl << flag2 << endl;

    cout << sizeof(bool) << endl;

    flag1 = !flag1;

    cout << flag1 << endl << flag2 << endl;

    cout << sizeof(flag1) << endl;//bool’s size is 1

    int flag3 = 0;

    cout << sizeof(flag3) << endl; // int=byte, which size is 4

    return 0;

    }

    //4-8 input

    #include <iostream>

    #include <string>

    //i=input

    //o = output

    using namespace std;

    int main() {

    //1.int’s input

    int a = 5;

    cin >> a; // the right used to input into some variables

    cout << “a turned to :” << a << endl;

    //2.float’s input

    double b = 5;

    cin >> b; // the right used to input into some variables

    cout << “b turned to :” << b << endl;

    //3.char’s input

    char c = 5;

    cin >> c; // the right used to input into some variables

    cout << “c turned to :” << c << endl;

    //4.string’s input

    string d = “”;

    cin >> d; // the right used to input into some variables

    cout << “d turned to :” << d << endl;

    //5.bool’s input

    bool e = false;

    cin >> e; // the right used to input into some variables

    cout << “e turned to :” << e << endl;

    return 0;

    //all the input must be legal

    }

  • #C++ Day3 Sep 11 2025

    #include <iostream>

    using namespace std;

    int main()

    // short 2字节     00       2 ^16   [-2 ^ 15 ~2 ^ 15 – 1]  [-32768~32767]

    // int 4字节       0000     2 ^ 16  [-2 ^ 31 ~2 ^ 31 – 1] [-2147483648~2147483647]

    // long 4字节 8字节 0000     2 ^ 16  [-2 ^ 31 ~2 ^ 31 – 1]

    // long long 8字节 00000000  2 ^ 16 [-2 ^ 63 ~2 ^ 63 – 1]

    //[l,r]

    // range:r-l+1

    //make it close to the range can save the space ,so watch out the range

    {

        short a = 32768; // will be get out of the range,and turn to the loop’s start -32768

        int b = 2147483648;

        long c = 1;

        long long d = 1;

        cout << “a=” << a << endl;

        a = 32769;

        cout << “a2=” << a << endl; // show out -32767

        cout << “b=” << b << endl;

        cout << “c=” << c << endl;

        cout << “d=” << d << endl;

        return 0;

    }

    //new reserver symbol sizeof()

    #include <iostream>

    using namespace std;

    int main()

    {

        short a = 1;

        int b = 1;

        long c = 1;

        long long d = 1;

        cout << sizeof(short) << endl;

        cout << sizeof(int) << endl;

        cout << sizeof(long) << endl;

        cout << sizeof(long long) << endl;

        cout << sizeof(a) << endl;

        cout << sizeof(b) << endl;

        cout << sizeof(c) << endl;

        cout << sizeof(d) << endl;

        return 0;

    }

    #include <iostream>

    #include <iomanip>

    #include <cmath>

    using namespace std;

    int main()

    #define eps 1e-7

    // float 0000 4bytes

    /// double 00000000 8bytes

    // if you want to solve the question,must use double ,or you will miss the acuracy

    // to judge the accuration of float, please make it minus in a small range

    {

        float a = 13.1415926f;

        double b = 13.1415926;

        cout << setprecision(10) << a << endl;

        cout << setprecision(10) << b << endl;

        a = 13.1415926f;

        b = 13.141592611111111111;

        cout << setprecision(10) << a << endl;

        cout << setprecision(30) << b << endl; // if you make it out of range ,can still display the wrong number

        cout << sizeof(a) << endl;

        cout << sizeof(b) << endl;

        double c = 1.5e5; // 1.5*10^5

        cout << c << endl;

        double d = 1.5e-5; // 1.5*10^-5

        cout << d << endl;

        double x = 1.0 / 123123111123123123 * 123123111123123123; // when the float is large enough,must will have the error

        cout << x << endl;

        if (fabs(x – 1) < 0.00000001)

        {

            cout << “one two” << endl;

        }

        if (fabs(x – 1) < eps)

        {

            cout << “one two” << endl;

        }

        return 0;

    }

  • 补码

    补码是计算机表示有符号整数的一种方式,核心作用是把 “减法” 变成 “加法”,让计算机只用 “加法器” 就能处理加减运算。下面用最通俗的方式解释:

    一、为什么需要补码?

    计算机里用二进制存数,有符号数的最高位是符号位0 表示正数,1 表示负数)。如果直接用 “符号位 + 原码”(比如 +3 是 0011-3 是 1011),做减法会很麻烦(比如 3-2 要专门设计减法逻辑)。

    补码的巧妙之处:用 “加法” 代替 “减法”。比如 3-2 可以变成 3 + (-2),只要给 -2 一个特殊的 “补码”,让加法的结果等价于减法,计算机就只需 “加法器” 即可。

    二、补码的计算规则

    • 正数的补码:和原码完全相同
      例:+5 的原码是 00000101(8 位),补码也是 00000101
    • 负数的补码:分两步(或用 “模” 理解):
      • 方法 1(步骤法):原码的符号位不变数值位取反,然后加 1
        例:求 -5 的补码:
        ① 原码:10000101(符号位 1,数值位 0000101);
        ② 数值位取反:1111010
        ③ 加 1:1111011
        ④ 最终补码:11111011(符号位保留 1)。
      • 方法 2(模的概念):补码 = 模 – 数的绝对值(更直观)。
        对于 8 位二进制,“模” 是 2⁸ = 256(因为 8 位最多表示 256 个数)。
        所以 -5 的补码 = 256 - 5 = 251,二进制是 11111011(和步骤法结果一致)。

    三、补码如何让 “减法变加法”?

    以 3-2 为例,等价于 3 + (-2)

    • 3 的补码:00000011(正数,补码 = 原码);
    • -2 的补码:用 “模 256 – 2” 得 254,二进制 11111110
    • 两者相加:00000011 + 11111110 = 100000001
    • 因为是 8 位,最高位的 1 会 “溢出”(超出 8 位范围),最终结果取低 8 位 00000001,即 1,和 3-2=1 一致。

    四、特殊情况:-128(8 位补码)

    8 位补码的范围是 -128 ~ 127。其中 -128 比较特殊:它没有 “原码”(因为原码表示范围是 -127 ~ 127),但补码可以表示为 10000000(用 “模 256 – 128 = 128”,二进制 10000000)。

    总结

    补码的核心是用加法代替减法,让计算机硬件更简单。记住:

    • 正数补码 = 原码;
    • 负数补码 = 模 – 绝对值(或 “符号位不变,数值位取反加 1”);
    • 计算时,直接用补码相加,结果自然等价于原数的加减。
  • #C++ Day2 Sep 10 2025

    #include <iostream>

    using namespace std;

    #define X “Vito写算法”

    #define Y “Deep Night”

    int main() {

    cout <<X <<endl <<Y<<endl ;

    //define constant can substitute sth

    }

    #include <iostream>

    using namespace std;

    #define X “Vito写算法”

    #define Y “Deep Night”

    #define Z 1+2

    #define G (1+2)

    const int x = 8;

    int main() {

    cout <<X <<endl <<Y<<endl ;

    cout << Z*Z<<endl; //would be 5,cause 1+2*1+2=5

    cout << G * G<< endl; // would be 9,cause you add the ()

    //x = (x + 1); //if add up the const ,this x can’t be modify

    //c++ is  upper and lower case sensitive 

    cout << x << endl;

    }

    #include <iostream>

    using namespace std;

    int main(){

    //int float;//it is wrong because you can’t use the reserve key as the symbol

    int a = 5;

    if (a == 6) {

    return -1;

    }

    return -2;

    }

    #include <iostream>

    using namespace std;

    int main() {

    int a12_ = 520;

    //int 9b_ = 22; //number can’t be the start of the literal

    int a = 5;

    int A = 8;

    cout << a << endl << A <<endl;

    int appleCount = 0;

    int chuangshijiejing = 0; //pinyin can be normal if you are in the chinese group

    #include <iostream>

    using namespace std;

    int main() {

    int a12_ = 520;

    //int 9b_ = 22; //number can’t be the start of the literal

    int a = 5;

    int A = 8;

    cout << a << endl << A <<endl;

    int appleCount = 0;

    int chuangshijiejing = 0; //pinyin can be normal if you are in the chinese group

    //variety Literal of C++

    /*1.case sensitive

    2.can not be started with number

    3.can not be the system reserve literal

    4.you can use word,number,_ as the variety Literal*/

    }

  • #C++ Day1 Sep 7 2025

    1. Leant how to install the environment 
    2. The dream is to code a game for me
    3. Found the reason of headache:fit the brain 
    4. Not the copy&paste, if you write more, you remember more
    5. Try to answer the question  by yourself, do not to ask other people the first time

    #include <iostream>

    using namespace std;

    int main()

    {

    cout << “Vito Algorithm” << endl <<endl <<endl; //endl is change the line

    return -12;

    }

    #include <iostream>

    //using namespace std;

    int main()

    {

    std::cout << “Vito Algorithm” << std::endl << std::endl << std::endl; //endl is change the line

    // i can use std:: before the cout and endl, so that i don’t need to script namespace

    //the namespace, which is used to divide the different codes that uses the same variety name 

    /*

    multiple notes

    */

    return -12;

    }

    #include <iostream>

    using namespace std;

    int main()

    {

    //std::cout << “Vito Algorithm” << std::endl << std::endl << std::endl; //endl is change the line

    //the definition of the variety:type name =origin value;

    //please give the variaty a origin value, if you didn’t do it, you are making errors when you are cout

    int a = 520;

    int b;

    cout << a << endl;

    cout << b << endl;

    return 0;

    }