1、设计模式以及适用的场景:工厂模式和单件模式
http://blog.csdn.net/liang19890820/article/details/70652858
https://blog.csdn.net/lbqbraveheart/article/details/7084509
2、虚函数:看代码输出应该是什么 ,析构适用虚函数和不适用虚函数分别为什么。
3、小模拟:带有括号的四则运算:例:1+2*(3+4*(5+6))-7。
#include <iostream>
#include <stack>
using namespace std;
int firstL(char c){
if(c=='-'||c=='+')return 1;
else if(c=='*'||c=='/')return 2;
else return 0;
}
int c(int x,int y,char c){
if(c=='+')return x+y;
if(c=='-')return x-y;
if(c=='*')return x*y;
if(c=='/')return x/y;
return -1;
}
int calculate(string s) {
stack<char>op;
stack<int>num;
s+='#';
int len=s.length();
int sum=0;
int re=0;
int f=0;
for(int i=0;i<len;i++){
if(s[i]>='0'&&s[i]<='9'){
sum=sum*10+(s[i]-'0');
f=1;
}
else{
if(f){
num.push(sum);
//cout<<"num: "<<sum<<endl;
sum=0;
f=0;
}
if(op.size()==0||s[i]=='('){
op.push(s[i]);
continue;
}
char tmpOp=op.top();
while(firstL(s[i])<=firstL(tmpOp)){
//cout<<"nowop: "<<s[i]<<endl;
//cout<<"lastop: "<<op.top()<<endl;
if(tmpOp=='('){
op.pop();
break;
}
op.pop();
int x=num.top();
num.pop();
int y=num.top();
num.pop();
re=c(y,x,tmpOp);
//cout<<re<<endl;
num.push(re);
if(op.size()==0)break;
tmpOp=op.top();
}
if(s[i]!=')')
op.push(s[i]);
}
}
op.pop();
int result=num.top();
num.pop();
return result;
}
string s;
int main(){
cin>>s;
cout<<calculate(s)<<endl;
}
4、一个圆上三个点处于同一个半圆的概率是多少?
求锐角三角形的概率,3/4。