9.15 | Study Notes

1.n converted to decimal binary decimal

The great God Code, only records (author blog links below, please indicate the source), is currently seeing the best version

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int t,i,j,k,n,tmp;
char str[N];
char dest[N];
void turn(char* str,int n)
{
    memset(dest,0,sizeof(dest));
    int len=strlen(str);
    for(i=len-1; i>1; i--)
    {
        int num=str[i]-'0';
        for(j=0;j<k||num!=0;j++)
        {
            tmp=10*num+(j<k?dest[j]-'0':0);
            dest[j]=tmp/n+'0';
            num=tmp%n;
        }
        k=j;
    }
    printf("0.%s\n",dest);
}

int main()
{
    cin>>str>>n;
    turn(str,n);
    return 0;
}

This code Reprinted from

https://blog.csdn.net/ACdreamers/article/details/9037763

 

2. Polish expression after yesterday did today against a data structures course, and finally the infix expression to engage in out, the process is extremely difficult, thanks to this open question data, the card is completely change the code point ......

Two key ideas:

1) use of stack thought, according to the press operator priority, if the priority is lower than the current top of the stack, the stack output, and finally press-fitting;

2) personally I think that the more important a pit, is subject only involves four basic binary operators, so the question minus or negative number will appear,

Here is my solution resulting postfix expression to check if the sign is '-' and is the first character expression, or it is not a number but in front of the front of the operator, indicating that this is a negative number,

You may be utilized -a = 0-a directly pressed into the deposit numbers 0 stack

Guess you like

Origin www.cnblogs.com/MissCold/p/11525171.html