?? getint(chengchu).txt
字號:
CString CCalcDlg::GetInt(CString str)
{
int count[10][2];for(int i=0;i<10;i++){count[i][0]=-1;count[i][1]=-1;}
/////以上初始化數組count,使之全為-1
int cou=0;//用于填充數組count的第一維
int sgn=0;//用于記錄無用的“(”和“)”,遇“(”加1,遇“)”減1。
for(i=str.GetLength()-1;i>=0;i--)
{
if(str.GetAt(i)==41)
{
if(sgn==0)
count[cou][0]=i;
sgn++;
}
if(str.GetAt(i)==40)
{
if(sgn==1)
{
count[cou][1]=i;
cou++;
}
sgn--;
}
}
//以上得到m_str是幾個(...)組成的
if(str.GetAt(0)=='+')str.Delete(0);
if(str.SpanIncluding("0123456789").GetLength()==str.GetLength())
return str;
CString s;s=str;
for(i=0;i<str.GetLength();i++)//負負得正;“--”號變“+”。
if(str.GetAt(i)=='-'&&i!=0&&str.GetAt(i+1)=='-')
{
str.Delete(i,2);
str.Insert(i,'+');
}
}
s=str;
for(i=0;i<str.GetLength();i++)//減法變加法;“-”號變“+-”。
{
if(str.GetAt(i)=='-'&&i!=0&&str.GetAt(i-1)!='+')
str.Insert(i,'+');
}
s=str;
for(i=0;i<str.GetLength();i++)//去掉多余加號
{
if(str.GetAt(i)=='+'&&str.GetAt(i+1)=='+')
{s.Delete(i);}
}
str=s;
// MessageBox(s);
if(cou==0)//式中沒有括號
{int cheng=0,chengdown=0,chengup=0;
CString chengstr,strup="9",strdown="8";
for(i=0;i<str.GetLength();i++)//實現乘法
{
if(str.GetAt(i)=='*')
{
for(chengup=i-1;chengup>=0;chengup--)
{
if(str.GetAt(chengup)<48||str.GetAt(chengup)>57)
{break; }
// strup.Format("%d\n%d",chengup,i);
}
for(chengdown=i+1;chengdown<str.GetLength();chengdown++)
{
if(str.GetAt(chengdown)<48||str.GetAt(chengdown)>57)
break;
}
break;
}
}
if(chengup&&chengdown)
{
strup=str.Mid(chengup+1,i-chengup-1);
strdown=str.Mid(i+1,chengdown-i-1);
cheng=GetData(strup)*GetData(strdown);
chengstr.Format("%d",cheng);
str.Delete(chengup+1,chengdown-chengup-1);
str.Insert(chengup+1,chengstr);
return GetInt(str);
}
// strdown.Format("chengup=%d\ni=%d\nchengdown=%d",chengup,i,chengdown);
// MessageBox(str);
// MessageBox(strdown);
// int chenganswer=
// GetData();
// chengstr.Format("%d",chenganswer);
// str.Delete(chengup+1,chengdown-chengup-1);
// str.Insert(chengup+1,chengstr);
int chu=0,chudown=0,chuup=0;
CString chustr,struup="9",strudown="8";
for(i=0;i<str.GetLength();i++)//實現乘法
{
if(str.GetAt(i)=='/')
{
for(chuup=i-1;chuup>=0;chuup--)
{
if(str.GetAt(chuup)<48||str.GetAt(chuup)>57)
{break; }
// strup.Format("%d\n%d",chengup,i);
}
for(chudown=i+1;chudown<str.GetLength();chudown++)
{
if(str.GetAt(chudown)<48||str.GetAt(chudown)>57)
break;
}
break;
}
}
if(chuup&&chudown)
{
strup=str.Mid(chuup+1,i-chuup-1);
strdown=str.Mid(i+1,chudown-i-1);
chu=GetData(struup)/GetData(strudown);
chustr.Format("%d",chu);
str.Delete(chuup+1,chudown-chuup-1);
str.Insert(chuup+1,chustr);
return GetInt(str);
}
for(i=0;i<str.GetLength();i++)//實現加法
{
if(str.GetAt(i)=='+')
{
CString temp1,temp2;int xx=0;
temp1=str.Left(i);
temp2=GetInt(str.Mid(i+1));
xx=GetData(temp1)+GetData(temp2);
s.Format("%d",xx);
// MessageBox(temp1);
return s;
}
}
}
return s;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -