输入一段代码,输出这段代码中包含的所有函数

ASCII码表

#include<iostream>
#include<fstream>
#include<cstring>
#include<cmath>
using namespace std; int total;//行数
//初始化数组为空
string str[10000]="";//预处理的数据
string str1[10000]="";//处理后数据
string temp[1000]=""; void Readin()
{//读入 :过滤注释,只读入有括号的行 fstream in;in.open("InFile.txt",ios::in);if(!in){cout<<"提示:打开文件失败。"<<endl;return;}int i=1;//str[0]空置不用 int n=0;//逐行存入数组 string readline;while (getline(in, readline)){int j=readline.length();int flag=0;//没有括号 //cout<<"当前行:"<<readline<<endl;for(n=0;n<j;n++){ //过滤注释 if(readline[n]=='/'&&readline[n+1]=='/') {//cout<<"过滤注释"<<endl;//system("pause");continue;}    //检索括号 if(readline[n]=='(') {//cout<<"发现括号:"<<readline[n]<<endl; flag=1; //system("pause");break;}}if(flag==1){//读入 str[i]=readline;i++;//cout<<"读入:"<<str[i]<<endl;   }} total=i;//cout<<total<<endl;//system("pause"); in.close();return;
}void Process()//处理原始数据,处理后数据存入新数组
{int i=1;//str[0]空置不用 //int extra=0;//存放一行多函数的行中,多出来的函数个数 //读取一行 while (i<total){int num=0;//包含函数数 //str1[i]=str[i];//cout<<"第"<<i<<"行处理前:"<<str[i]<<endl;   //非字母字符识别int n=0; int j=str[i].length();int startpos=0; int endpos=0; for(n=0;n<j;n++){//cout<<"处理中:"<<"n:"<<n<<"值:"<<str[i][n]<<endl; //判断注释if(str[i][n]=='/'&&str[i][n+1]=='/') {//cout<<"发现注释"<<endl;break;}//过滤非字母或数字if((str[i][n]<'a'||str[i][n]>'z')&&(str[i][n]<'A'||str[i][n]>'Z')&&(str[i][n]<'0'||str[i][n]>'9')&&str[i][n]!='('&&str[i][n]!='_')//&&str[i][n]!='.'{startpos=n+1;//cout<<"startpos:"<<startpos<<endl;}//是括号 if(str[i][n]=='('){endpos=n-1;//cout<<"endpos:"<<endpos<<endl;if(endpos>startpos){num++;//cout<<"这是该行的第"<<num<<"个函数"<<endl;int len=endpos-startpos+1;str1[i]=str[i].substr(startpos,len)+" "+str1[i];//cout<<"处理后:"<<str1[i]<<endl;//初始化 startpos=n+1;endpos=0;//extra++; }else{//cout<<"这个不是函数的括号,继续读 "<<endl;//这个不是函数的括号,继续读 startpos=n+1;continue;}//处理后 //cout<<"处理后:"<<str1[i]<<endl;    //system("pause"); //continue; //break;}      }i++;     }
}void Print()
{//写入文件 fstream out;out.open("temp.txt",fstream::out | ios_base::trunc);for(int i=1;i<=total;i++){//if(str[i].length()!=0) cout<<"处理前"<<str[i]<<endl; if(str1[i].length()!=0) {int flag=0;//无空格 int pos=0;//cout<<"当前行:"<<str1[i]<<endl;//判断有无空格 for(int n=0;n<str1[i].length();n++){//cout<<n<<endl;if(str1[i][n]==' ') {//cout<<"有空格"<<"n:"<<n<<" pos:"<<pos<<endl; //cout<<str1[i].substr(pos,n-pos)<<endl;out<<str1[i].substr(pos,n-pos)<<endl;pos=n+1;flag=1; }} //if(flag==0)//cout<<str1[i]<<endl; } }out.close();
}void Print2()
{//写入文件 fstream out;out.open("temp.txt",fstream::out | ios_base::trunc);for(int i=1;i<=total;i++){out<<temp[i]<<endl;cout<<temp[i]<<endl;}out.close();
}int Check(string L[],string a)
{for(int i=1;i<1000;i++){if(L[i]=="")break; if(a==L[i]){//cout<<"有重复:"<<i<<endl;return i;//返回重复单词在数组中的位置 }}//cout<<"没有找到"<<endl;return 0;
}void Readin2()
{fstream in;in.open("temp.txt",ios::in);if(!in){cout<<"提示:打开文件失败。"<<endl;return;}int i=1;//str[0]空置不用 int n=0;//逐行存入数组 string readline;while (getline(in, readline)){ if(Check(temp,readline)==0){temp[i]=readline;i++;}}total=i;in.close();return;
}int main()
{Readin();Process();Print();Readin2();Print2();return 0;
}

输入

输出

示例一

IMPLEMENT_DYNCREATE
BEGIN_MESSAGE_MAP
ON_COMMAND
ON_WM_TIMER
END_MESSAGE_MAP
CMyCloth20071121View
InitialParticleSys
InitialSpringSys
PreCreateWindow
OnDraw
GetDocument
ASSERT_VALID
RenderSence
StartRender
OnPreparePrinting
DoPreparePrinting
OnBeginPrinting
OnEndPrinting
AssertValid
Dump
RUNTIME_CLASS
IsKindOf
ASSERT
DrawBackground
IsChangedFixState
if
InitialParticle
ComputeForce
CollisionHandle
ContactionHandle
EulerMethod
TextureCloth
DrawVertexes
DrawSprings
OnOperationRunning
SetTimer
OnTimer
Invalidate
OnOperationClothproperty
bDarwVertex
bDarwSpring
bDrawShearSprings
bDarwFlexionSprings
bUsingShearSpring
bUsingFlexionSpring
bFixed
DoModal
OnOperationResetcloth
ResetProperty

示例二

IMPLEMENT_DYNCREATE
CGLView
m_dAspectRatio
m_rotFi
m_rotTheta
m_rotFiR
m_rotThetaR
m_fScale
m_bRenderAxis
m_bRenderDebugInfo
m_bRenderStatInfo
m_bRenderHelpInfo
m_bWireFrame
m_bCullFace
if
BEGIN_MESSAGE_MAP
ON_WM_CREATE
ON_WM_SIZE
ON_WM_ERASEBKGND
ON_WM_LBUTTONDOWN
ON_WM_LBUTTONUP
ON_WM_MOUSEMOVE
ON_WM_MOUSEWHEEL
END_MESSAGE_MAP
OnDraw
RenderSence
AssertValid
Dump
PreCreateWindow
OnCreate
CClientDC
_SetupPixelFormat
GetSafeHdc
GetPixelFormat
sizeof
DescribePixelFormat
wglCreateContext
wglMakeCurrent
SetupRC
ASSERT
ChoosePixelFormat
_T
AfxMessageBox
SetPixelFormat
DestroyWindow
wglDeleteContext
OnSize
GLSize
Invalidate
OnEraseBkgnd
glEnable
glCullFace
glClearColor
glClearDepth
glPolygonMode
glDisable
glViewport
glMatrixMode
glLoadIdentity
gluPerspective
gluLookAt
glClear
glTranslatef
glRotatef
glScalef
glColor3f
glutWireCube
glBegin
glVertex3f
glEnd
glFinish
SwapBuffers
DrawBackground
StartRender
glFlush
OnLButtonDown
OnLButtonUp
OnMouseMove
while
OnMouseWheel

示例三

CPhyEnv
for
SetProperty
InitCollisionPlane
if
free
setVector
InitialParticleSys
sizeof
malloc
IsFixed
InitialParticle
InitialSpringSys
InitialStructuralSpring
InitialShearSpring
InitialFlexionSpring
DrawVertexes
glPointSize
glColor3f
glBegin
glVertex3f
glEnd
DrawSprings
glLineWidth
ComputeSpringsForce
VectorLength
ComputeForce
ApplyWind
UpdateStates
AdjustSpringLength
EulerMethod
MidPointMethod
VectorDif
OneVectorLength
DotMultiply
Normalize
ResetProperty
IsChangedFixState
CollisionDetect
ScaleVector
CollisionHandle
VectorAdd
while
ContactionDetect
ContactionHandle
LoadBMP
fopen
fclose
auxDIBImageLoad
LoadGLTextures
memset
glGenTextures
glBindTexture
glTexImage2D
glTexParameteri
TextureCloth
glEnable
glTexCoord2f
glDisable
sin
fabs

总结:

⚪去重

原本使用了一种去重算法:

遍历数组,从第一个1元素开始,依次与其后所有的元素中比较,如果相等,就把之后所有元素向前移动一位。

这种方法过于愚蠢了,用了三个for循环,时间复杂度是O(n^3),在单个数组中通过移位覆盖去重,时间复杂度太高了。

后来发现有一种可行的算法,用空间换时间:

再建一个数组。从第一个数组拿一个元素,遍历第二个数组, 如果第二个数组中不存在这个元素,则将该元素放入第二个数组,这样就达到了去重的目的。

用了两个for循环,这样的时间复杂度是O(n^2)。

⚪最初一行只能分析出第一个函数,后来通过更新startpos和endpos的方式,能够识别多个函数并存放在一个字符数组元素中,后续再展开为多个元素。

附:

在学习新的代码时,先用上面的脚本提取函数,再用下面这个脚本快速查询该函数,提高学习效率

批处理 快捷键搜索剪切板内容

C++ 提取代码中的函数相关推荐

  1. python里compile的作用_Python代码中compile()函数具有哪些功能呢?

    摘要: 下文讲述Python代码中compile()函数的功能说明,如下所示: compile()函数功能说明 compile()函数功能: 用于将一个字符串编译为字节代码 compile()函数语法 ...

  2. python反余弦函数_Python代码中acos()函数有什么功能呢?

    摘要: 下文讲述Python代码中acos()函数的简介说明,如下所示: acos()函数功能 用于计算出x的反余弦弧度值 acos()函数语法 math.acos(x) ---------参数说明- ...

  3. python pow函数用法_Python代码中pow()函数具有哪些功能呢?

    摘要: 下文讲述Python代码中pow()函数的功能说明,如下所示: pow函数功能说明 pow() 函数用于 计算 xy(x 的 y 次方) 的值 pow函数语法: import math mat ...

  4. python中seed的用法什么作用_Python代码中seed()函数有什么功能呢?

    摘要: 下文讲述Python代码中seed()函数的简介说明,如下所示: seed()函数功能 用于改变随机数生成器的种子, 常用于其它随机函数之前运行此函数 seed()函数语法 seed.seed ...

  5. python中cos函数_Python代码中cos()函数有什么功能呢?

    摘要: 下文讲述Python代码中cos()函数的简介说明,如下所示: cos()函数功能 用于计算出x 弧度-所对应的的余弦值 cos()函数语法 math.cos(x) ---------参数说明 ...

  6. python中degree什么意思_Python代码中degrees()函数有什么功能呢?

    摘要: 下文讲述Python代码中degrees()函数的简介说明,如下所示: degrees()函数功能 用于将弧度值转换为对应的角度 degrees()函数语法 math.degrees(x) - ...

  7. python中tan怎么表示_Python代码中tan()函数有什么功能呢?

    摘要: 下文讲述Python代码中tan()函数的简介说明,如下所示: tan()函数功能 用于计算出x 弧度-所对应的的正切值 tan()函数语法 math.tan(x) ---------参数说明 ...

  8. python中format函数作用_Python代码中format函数具有哪些功能呢?

    摘要: 下文讲述Python代码中format函数的功能说明,如下所示: format函数功能说明 format函数功能: 用于格式化字符串 format函数语法: format采用{} 和 : 来代 ...

  9. 如何提取代码中的中文字符串

    前言 在一般情况下,程序中的中文字符串都是写在某个文件中读取(例如json),但是大部分时候我们都是直接写入到代码中,这个时候如果我们想把字符串提取出来就需要一个一个去找,或者通过IDE提供的字符串匹 ...

最新文章

  1. R语言使用fs包的file_info函数查看文件元信息(属性信息)、使用file_chmod函数修改文件的权限、使用file_chown函数修改文件的所有者
  2. yum安装php和apache先装哪个,yum如何安装apache与php
  3. vue实现多行数据提交_2020年大厂面试指南 Vue篇
  4. MySQL复制数据库
  5. 使用solr的完整流程
  6. qt交叉编译环境搭建方法
  7. 置信区间估计 预测区间估计_估计,预测和预测
  8. python学籍管理系统 flask_taskday05-Python之flask学习 web开发最基本的需要(特别详细且适用)...
  9. 网站“拍照”备案月底恐难实施
  10. “软下来”的苹果和小米能否拯救智能手机的焦虑? | 畅言
  11. 第20章 TCP的成块数据流
  12. 【Jsp】第七课 Jsp内置对象的学习和使用
  13. python数据分析入门到实战知了课堂_价值699元知了课堂零基础学Python 21天搞定Python分布爬虫...
  14. c语言编程运动会分数统计系统报告,C语言课程设计报告运动会分数统计系统.pdf...
  15. 数字时钟word clock Mac设置教程
  16. 菜花这样做,就着它吃光三碗饭
  17. spring加载不到.properties中属性问题(spring中类:PropertyPlaceholderConfigurer出现多次)
  18. delphi 企业微信消息机器人_消息通知支持企业微信、钉钉机器人,MeterSphere v1.4.0发布...
  19. 负数在计算机中如何表示,计算机中负数为什么用补码表示?
  20. autojs教程:找图函数

热门文章

  1. 人生的诗·335~339节
  2. 微信小程序真机预览图片图标无法显示
  3. PHP语言是什么语言及能解决当下什么问题-动态更新
  4. 根据出生年月日算出实际的月龄
  5. anaconda环境配置与windows环境下pip使用方法
  6. ChatGPT官方鉴别器紧急发布!当代自相矛盾,不想却遭遇群嘲
  7. 现在有哪些好用的企业报表软件?
  8. 基于matlab介绍传感器融合和跟踪工具箱中用于评估跟踪器性能的不同定量分析工具(附源码)
  9. CSS的文本属性阴影效果
  10. 如何删除电脑上卸载软件的残留文件,清理软件残留?