DS1-1
#include <iostream>
#include <algorithm>
using namespace std;
struct duo{
int xi,mi;
}a[1000],b[1000],c[1000];
bool cmp(duo x,duo y){
return x.mi>y.mi;
}
int main(){
int n,m;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].xi>>a[i].mi;
}
sort(a,a+n,cmp);
cin>>m;
for(int i=0;i<m;i++){
cin>>b[i].xi>>b[i].mi;
}
sort(b,b+n,cmp);
int cnt=0;
for(int i=0,j=0;i<n+m&&j<n+m;){//枚举
if(b[j].mi>a[i].mi) {c[cnt].xi=b[j].xi,c[cnt].mi=b[j].mi,j++,cnt++;continue;}
if(b[j].mi<a[i].mi) {c[cnt].xi=a[i].xi,c[cnt].mi=a[i].mi,i++,cnt++;continue;}
if(b[j].mi==a[i].mi) {c[cnt].xi=b[j].xi+a[i].xi,c[cnt].mi=a[i].mi,i++,j++,cnt++;continue;}
}
for(int i=0;i<n+m;i++){
if(c[i].xi!=0) cout<<c[i].xi<<" "<<c[i].mi<<endl;
}
return 0;
}
DS2-1
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair <int,int> PII;
PII s[1000];
int top,rf;
bool check(int t){
if(top==0) return 0;
return s[top--].first=t;
}
int main(){
string a;
cin>>a;
for(int i=0;i<a.size();i++){
if(a[i]=='('){
s[++top].first=1;
s[top].second=i;
}
if(a[i]==')'){
if(!check(1)){
cout<<"right "<<i<<" ";
rf=1;//表明右括号匹配失败
}
}
}
if(rf) return 0;
else{
if(top==0){
cout<<"ok";
}
else{
cout<<"left ";
while(top!=0){
cout<<s[top--].second<<" ";
}
}
}
return 0;
}
DS2-2
#include <iostream>
#include <vector>
using namespace std;
int main(){
string a;
cin>>a;
vector <int> C;
for(int i=0;i<a.size();i++){
if(a[i]!='+'&&a[i]!='-'&&a[i]!='*'&&a[i]!='/'){
C.push_back(a[i]-'0');
}
if(a[i]=='+'){
int x=C.back();
C.pop_back();
int y=C.back();
C.pop_back();
C.push_back(x+y);
}
if(a[i]=='-'){
int x=C.back();
C.pop_back();
int y=C.back();
C.pop_back();
C.push_back(y-x);
}
if(a[i]=='*'){
int x=C.back();
C.pop_back();
int y=C.back();
C.pop_back();
C.push_back(x*y);
}
if(a[i]=='/'){
int x=C.back();
C.pop_back();
int y=C.back();
C.pop_back();
C.push_back(y/x);
}
}
cout<<C[0];
return 0;
}
A1-1:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a[3];
int main(){
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<a[2]<<" "<<a[1]<<" "<<a[0];
return 0;
}
A1-3:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int y,m,d;
int main(){
cin>>y>>m;
if(m==2){
d=28+(y%4==0&&y%100||y%400==0);
}
else if(m==4||m==6||m==9||m==11) d=30;
else d=31;
cout<<d;
return 0;
}
A2-2 :
#include <iostream>
using namespace std;
const int N =50;
int n;
int fib[N];
int main(){
cin>>n;
fib[0]=1;
fib[1]=1;
for(int i=2;i<n;i++) fib[i]=fib[i-1]+fib[i-2];
for(int i=0;i<n;i++) cout<<fib[i]<<" ";
return 0;
}
A3-2:
#include <iostream>
using namespace std;
int main(){
int n,flag=0;
cin>>n;
for(int i=2;i<n;i++){
if(n%i==0){
flag=1;
break;
}
}
if(!flag) cout<<"Yes";
else cout<<"No";
return 0;
}
A3-4:
#include <iostream>
#include <vector>
using namespace std;
bool check(int x){
for(int i=2;i<x;i++){
if(x%i==0) return false;
if((x%2)==0) return false;
}
return true;
}
int main(){
int n;
cin>>n;
vector <int> C;
for(int i=2;i<n;i++){
if(check(i)) C.push_back(i);
}
for(int i=0;i<C.size();i++){
for(int j=i;j<C.size();j++){
if(C[i]+C[j]==n) cout<<C[i]<<"+"<<C[j]<<"="<<n<<endl;
}
}
return 0;
}