C++经典编程题Word文档格式.docx
《C++经典编程题Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++经典编程题Word文档格式.docx(76页珍藏版)》请在冰豆网上搜索。
j<
k2;
j++)
k3=(k3*10+(p[j]-48));
pp.push_back(k3);
jiajian.push_back(pp.size());
pp.push_back(p[i]);
k1=i+1;
}
elseif(p[i]=='
*'
/'
k3=((k3*10)+(p[j]-48));
chenchu.push_back(pp.size());
elseif(i==n-1)
=k2;
i++;
}
while(!
chenchu.empty())
k1=chenchu.front();
k2=pp[k1-1];
k3=pp[k1+1];
if(pp[k1]=='
j=k2*k3;
else
j=k2/k3;
pp[k1-1]=j;
for(i=k1;
i<
pp.size()-2;
i++)
pp[i]=pp[i+2];
pp.pop_back();
list<
:
iteratorpos=chenchu.begin();
while(pos!
=chenchu.end())
*pos=*pos-2;
++pos;
pos=chenchu.begin();
chenchu.erase(pos);
iteratortra=jiajian.begin();
for(;
tra!
=jiajian.end();
tra++)
if(*tra>
k1)
{
while(tra!
=jiajian.end())
{
*tra=*tra-2;
++tra;
}
break;
}
jiajian.empty())
iteratorpos=jiajian.begin();
k1=jiajian.front();
j=k2+k3;
j=k2-k3;
pos=jiajian.begin();
jiajian.erase(pos);
if(pp.size()==1)
returnpp[0];
else
return-11111111111;
}
计算结果为:
2.带括号的计算程序
intSuanshu2(char*p)
jiajian,chenchu,jiajian2,chenchu2;
pp,leftkuo,rightkuo;
if(k1==k2)
jiajian.push_back(pp.size());
pp.push_back(p[i]);
else
pp.push_back(k3);
if(k1!
=k2)
chenchu.push_back(pp.size());
('
leftkuo.push_back(pp.size());
)'
rightkuo.push_back(pp.size());
if(leftkuo.size()!
=rightkuo.size())
return-11111111111;
leftkuo.empty())
n=rightkuo[0];
k3=leftkuo[0];
for(j=leftkuo.size()-1;
j>
=0;
j--)
if(leftkuo[j]<
k3=leftkuo[j];
i=0;
//while(n)
intm1,m2,m3=0;
for(j=k3+2;
n;
j+=2)
if(pp[j]=='
||pp[j]=='
jiajian2.push_back(j);
elseif(pp[j]=='
chenchu2.push_back(j);
while(!
chenchu2.empty())
m1=chenchu2[0]-1;
m2=chenchu2[0]+1;
if(pp[chenchu2[0]]=='
m3=pp[m1]*pp[m2];
else
m3=pp[m1]/pp[m2];
pp[m1]=m3;
//移°
?
动¡
¥
整?
体¬
表À
¨
ª
达ä
式º
for(j=chenchu2[0];
pp[j]=pp[j+2];
pp.pop_back();
chenchu2
for(j=0;
chenchu2.size()-1;
chenchu2[j]=chenchu2[j+1]-2;
chenchu2.pop_back();
jianjian2
m2=strlen(p);
jiajian2.size();
if(jiajian2[j]>
(m1+1))
{
m2=j;
break;
}
for(j=m2;
jiajian2[j]=jiajian2[j]-2;
jiajian
jiajian.size();
if(jiajian[j]>
jiajian[j]=jiajian[j]-2;
chenchu
chenchu.size();
if(chenchu[j]==(m1+1))
chenchu.size()-1;
chenchu[j]=chenchu[j+1]-2;
chenchu.pop_back();
左Á
®
括¤
¡
§
号?
leftkuo
leftkuo.size();
if(leftkuo[j]>
leftkuo[j]=leftkuo[j]-2;
右®
°
rightkuo.size();
if(rightkuo[j]>
rightkuo[j]=rightkuo[j]-2;
jiajian2.empty())
m1=jiajian2[0]-1;
m2=jiajian2[0]+1;
if(pp[jiajian2[0]]=='
m3=pp[m1]+pp[m2];
m3=pp[m1]-pp[m2];
for(j=jiajian2[0];
jianjian
if(jiajian[j]==jiajian2[0])
jiajian.size()-1;
jiajian[j]=jiajian[j+1]-2;
jiajian.pop_back();
jiajian2
jiajian2.size()-1;
jiajian2[j]=jiajian2[j+1]-2;
jiajian2.pop_back();
if(chenchu[j]>
chenchu[j]=chenchu[j]-2;
rightkuo
//此ä
时º
À
就¨
是º
一°
对?
包ã
¹
含?
一°
个?
数º
y字Á
了¢
?
ê
k1=k3;
k2=rightkuo[0];
if(k1+2==k2)
pp[k1]=pp[k1+1];
for(j=k1+1;
k2)
if(leftkuo[j]==k1)
leftkuo.size()-1;
leftkuo[j]=leftkuo[j+1]-2;
leftkuo.pop_back();
if(rightkuo[j]==k2)
rightkuo.size()-1;
rightkuo[j]=rightkuo[j+1]-2;
rightkuo.pop_back();
return-000;
}
}
//括¤
执¡
ä
行D结¨
¢
束º
,ê
开a始º
行D乘?
除y运?
算?
k1=chenchu[0];
//移°
chengchu表À
for(i=0;
chenchu[i]=chenchu[i+1]-2;
chenchu.pop_back();
jiajian表À
j=strlen(p);
for(i=0;
if(jiajian[i]>
j=i;
for(i=j;
jiajian[i]=jiajian[i]-2;
k1=jiajian[0];
jiajian[i]=jiajian[i+1]-2;
jiajian.pop_back();
return-000;
实验结果为:
2.打印一个N*N的方阵,N为每边
N=15打印出下面图形
字符的个数(3<N<20=,要求最
TTTTTTTTTTTTTTT
外一层为"
T"
第二层为"
J"
从第三层
TJJJJJJJJJJJJJT
起每层依次打印数字1,2,3,...
TJ11111111111JT
(右图以N为15为例)
TJ12222222221JT
TJ12333333321JT
TJ12344444321JT
TJ12345554321JT
TJ12345654321JT
TJ12222222221JT
实验程序为:
stack>
queue>
deque>
voidprintN(intN)
inti,j,k1,k2,m