P3156 【深基15.例1】询问学号
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n,m,x,y;
cin>>n>>m;
vector<int>v;
for(int i=0;i<n;i++){
cin>>x;
v.push_back(x);
}
for(int i=0;i<m;i++){
cin>>y;
cout<<v[y-1]<<endl;}
return 0;
}
P3613 【深基15.例2】寄包柜
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<vector<int> > a;
int h,n,m,k,i,j;
cin>>n>>m;
a.resize(n+1);
for(int x=1;x<=m;x++){
cin>>h;
if(h==1){
cin>>i>>j>>k;
if(a[i].size()<j+1)a[i].resize(j+1);
a[i][j]=k;}
else{
cin>>i>>j;
cout<<a[i][j]<<endl;}}
return 0;
}
P1449 后缀表达式
#include<iostream>
#include<stack>
#include<cmath>
using namespace std;
stack<int> s;
int main(){
char c;
int l,r,t;
cin>>c;
while(c!='@'){
l=0;
if(c>='0'&&c<='9'){
while(c>='0'&&c<='9'){
t=c-'0';
l=l*10+t;
cin>>c;}}
if(c=='.')s.push(l);
else {
r=s.top();
s.pop();
l=s.top();
s.pop();
if(c=='+')s.push(l+r);
if(c=='-')s.push(l-r);
if(c=='*')s.push(l*r);
if(c=='/')s.push(l/r);}
cin>>c;}
cout<<s.top();
return 0;
}
P1996 约瑟夫问题
#include<iostream>
using namespace std;
int main(){
int n,m,a[110]={0},x=0,y=0;
cin>>n>>m;
while(y<n){
for(int i=1;i<=m;i++){
if((x+1)<=n)x++;
else x=1;
while(a[x]){
if((x+1)<=n)x++;
else x=1;}}
y++;
a[x]=1;
cout<<x<<" ";}
return 0;
}