⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commun.cpp

📁 The subject which is to us propos¨&brvbar is as follows: calculation of the degr¨&brvbar d&iexcl &ma
💻 CPP
字号:

#include "stdio.h"
#include "stdlib.h"
#include <set>
#include <map>
#include <vector>

#include "Commun.h"

#include <iostream>
using namespace std;

/*
int FindCaractere(char* ligne, char caractere)
Returns the position of the first string "caractere" in the string "line"
*/
int FindCaractere(char* line, char* caractere)
{
    char* pLine = line;
    
    int nLineLength = strlen(line);
    int nCaractereLength = strlen(caractere);
    
    for (int i=0; i<nLineLength; i++)
    {
        if (strlen(pLine) >= nCaractereLength)
        {
            if (strncmp(pLine, caractere, nCaractereLength) == 0)
                return i;
            pLine++;
        }
        else
            break;
    }
    
    return -1;    
}

int FindFirstCaractereNot(char* line, char caractere)
{
    char* pLine = line;
    
    int nLineLength = strlen(line);
    
    for (int i=0; i<nLineLength; i++)
    {
        if (line[i] != caractere)
            return i;
    }
    
    return -1;    
}

void EraseCaractere(char* &str, char car)
{
    int nFirstNotBlank = FindFirstCaractereNot(str, car);
    
    str = &str[nFirstNotBlank];
    
    int length = strlen(str);
    for (int i=0; i<length; i++)
    {
        if (str[i] == car)
        {
            str[i] = '\0'; // End of line
            break;
        }            
    }
}

char* CutAndRetrieved(char* c, char* &pSuiv)
{
    char* pBegin = pSuiv;
    
    int placeInWord = FindCaractere(pSuiv, c);
    
    pSuiv = &pSuiv[placeInWord+1];
    
    strtok(pBegin, c);
    
    return pBegin;
}

char* GetNextAtom(char* &sSetOfAtom)
{
  char* atomReturn;
  bool parentheseTrouve = false;
  int strlength = strlen(sSetOfAtom);
  int posEndAtom = strlen(sSetOfAtom);

  // Search the end of the first atom
  for (int i=0; i<strlength; i++)
  {
    if (sSetOfAtom[i] == '(') // We have a '(' so we'll go through sSetOfAtom until a ')'
    {
	parentheseTrouve = true;
    }

    if (sSetOfAtom[i] == ',' && !parentheseTrouve) // We've got the beginning of a new atom so we stop the thread
    {
        posEndAtom = i;
        break;
    }

    if (sSetOfAtom[i] == ')' && parentheseTrouve) // End of atom. Break the thread
    {
        i++; // We want the ) too
	posEndAtom = i;
        break;
    }
  }

  atomReturn = sSetOfAtom;

  if (posEndAtom >= strlength) // Appends when the current body is only containing one atom
  {
    sSetOfAtom = "";
    return atomReturn;
  }

  sSetOfAtom = &sSetOfAtom[posEndAtom + 1];
  atomReturn[posEndAtom] = '\0';
  
  // Prepare the next call to GetNextAtom with deleting blank spaces
  // and the first comma in front of the next atom
  strlength = strlen(sSetOfAtom);
  int nDebutNewAtom = 0;
  for (int i=0; i < strlength; i++)
  {
    if (sSetOfAtom[i] == ',')
    {
        nDebutNewAtom = i+1;
        break;
    }

    if (sSetOfAtom[i] != ' ')
    {
        nDebutNewAtom = i;
	break;
    }
  }

  sSetOfAtom = &sSetOfAtom[nDebutNewAtom];

  // atomReturn like : p(1,2,1,...,5)
  // sSetOfAtom like : next1(...), next2(...), ...

  return atomReturn;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -