赞
踩
#include<bits/stdc++.h> using namespace std; int main() { for(int a=1;a<=6;++a){ for(int b=0;b<=9;++b){ for(int c=1;c<=6;++c){ for(int d=0;d<=9;++d){ int x=a*1000+b*100+c*10+d; int y=c*1000+a*100+b*10+d; if(x+y==7856){ cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; } } } } } return 0; }
#include<bits/stdc++.h> using namespace std; int reverse(int number){ vector<int> nums; while(number){ nums.push_back(number%10); number/=10; } number=0; int temp=1; for(int i=nums.size()-1;i>=0;--i){ number+=nums[i]*temp; temp*=10; } return number; } int judge(int x,int y){ return (reverse(x)+reverse(y))==(x+y); } int main() { vector<int> xs,ys; int n,x,y; cin>>n; for(int i=0;i<n;++i){ cin>>x>>y; if(judge(x,y)){ xs.push_back(x); ys.push_back(y); } } if(xs.size()){ for(int i=0;i<xs.size();++i){ cout<<xs[i]<<" "<<ys[i]<<endl; } }else{ cout<<"none"; } return 0; }
#include<bits/stdc++.h> using namespace std; vector<int> p; int num,price; int cnt; void f(int i,int price,vector<int>& buy){ if(i==num&&price!=0){ return; } if(price==0){ ++cnt; for(int j=0;j<buy.size();++j){ cout<<buy[j]<<" "; } cout<<endl; return; } f(i+1,price,buy); if(price>=p[i]){ buy.push_back(i); f(i+1,price-p[i],buy); buy.pop_back(); } } int main() { cin>>num>>price; for(int i=0;i<num;++i){ int temp; cin>>temp; p.push_back(temp); } vector<int> buy; f(0,price,buy); cout<<cnt; return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。