After class, practice (advancement) 1017. -1+I advance naive “Programming Thinking and Practice” personal learning notes

2022-12-30   ES  

Question Reference 1014. I-1 Improvement (EASY)
but this is the transformation from decimal to I-1 input
在这里插入图片描述

① Transfer data
This topic is considering
A whether there is an integer
b integer positive and negative
C whether there are virtual numbers
d virtual number of positive and negative
So consider whether there is any situation in it in it

② to transform the remainder
Since this question only needs to be transformed in I-1 in, I only conduct special treatment when setting the COM class, that is,
在这里插入图片描述
But note that when the remaining number is obtained, we need to put the real number R first -1 and store the remaining number = 1, and then remove it, otherwise due to the INT type/2

if((real + imag) % 2 != 0)
           {
    
            remain = 1;
            real--;
            //cout <<"???"<<r << i<<remain<<endl;
           }

#include<iostream>
#include<stack>
using namespace std;

class com
{
    
public:
    long long i;
    long long r;
    int rema;

    com(long long i, long long r,int remain)
    {
    
        this->i = i;
        this->r = r;
        this->rema = remain;
    }
    com operator^(const com &c)const
    {
    
        int has_mod = 0;
        long long real = r;
        long long imag = i;
        int remain;
        if((real + imag) % 2 != 0)
            {
    
            remain = 1;
            real--;
            //cout <<"???"<<r << i<<remain<<endl;
            }
        else
            {
    
            remain = 0;
            //cout <<"!!!"<<r << i<<remain << endl;
            }
        // Since I only consider -1+i here, I will not consider other data
        long long r1 = (imag - real) / 2 ;
        long long i1 = (-imag - real) / 2;
        
        return com(i1,r1,remain);//
    }

};

void trans(long long r, long long i)
{
    
    stack<int>bin;
    com translate(i,r,0);
    com base(1,-1,0);

    while(translate.i || translate.r)
    {
    
        translate = translate ^ base;
        //cout << "i "<<translate .i <<" r "<<translate.r << " remain "<<translate.rema << endl;
        bin.push(translate.rema);
    }
    while(!bin.empty())
    {
    
        cout << bin.top();
        bin.pop();
    }

}

int main()
{
    
    // Process string convert to plural
    string a;
    cin >> a;
    if(a == "0")
    {
    cout << 0;
    return 0;}
    
    
    char c;
    long long i = 0;
    long long r = 0;

    int pos_r = 0;
    int pos_i = 0;
    int is_r = 0;
    int is_i = 0;
    int neg_r = 0;
    int neg_i = 0;

    int len = a.length();
    int j = len - 1;// Watch from the back to see if you can meet '.' I '+''- '

    if(a[j] == 'i')
    {
    
        is_i = 1;
        j--;    
    }
    if(is_i)
    {
       
        stack<int> bin;
        if(a[j] == '-' || a[j] == '+' || j == -1)
            i = 1;

        for(; a[j] != '+' && a[j] != '-' && j != -1 ; j--)
        // Considering whether there is still real numbers before the dwitzing of the dwitzing virtual number 2
        {
    
            bin.push(a[j] - '0');
        }
        while(!bin.empty())
        {
       
            int temp = bin.top();
            i *= 10;
            i += temp;
            bin.pop();
        }

        (j == -1 || a[j] == '+')? pos_i : neg_i = 1;
        if(a[j] == '-')
        {
    
            neg_i = 1;
        }

        if(neg_i)
        {
    
            i = -i;
            if(j == 0)
            {
    trans(r,i);return 0;}// No real number
        }

        if(j == -1)// No real number
        {
    trans(r,i);return 0;}

        j--;// There are real numbers, then let the position a little before, whether it is+or-
    }


    // If you can still execute the following content description, there are real numbers,
    stack<int>qqq;
    for(; j > 0; j--)
    {
    
        qqq.push(a[j] - '0');
        
    }
    if(a[0] == '-')
    {
    
        neg_r = 1;
    }
    else
    {
    
        qqq.push(a[0] - '0');
    }
    while(!qqq.empty())
    {
    
        int temp =qqq.top();
        r *= 10;
        r += temp;
        qqq.pop();
    }
    if(neg_r)
    {
    r = -r;}
    

    
    FLAG:
    //cout << "i " << i <<" r "<<r<<endl;
    trans(r,i);
}

source

Random Posts

[Design mode Learning note] Filter mode

SQLDIAG-Configuration File-Extension

When you can’t come down from github git clone, report the Permission Denied (PublicKey). Fatal: Could not red from remote repository.

java concurrent programming art-Chapter 4 Note

How to use C# to crawl “China Book Network -Computer and Internet Book Sales List”!