大美数
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N,input;
cin>>N;
for(int i=0;i<N;++i){
bool flag=false;
vector<int> save;
cin>>input;
for(int j=1;j<=input;++j){
if(input%j==0){
save.push_back(j);
}
}
if(save.size()<4)cout<<"No"<<endl;
else{
for(int j=0;j<save.size()&&!flag;++j){
for(int k=j+1;k<save.size()&&!flag;++k)
for(int m=k+1;m<save.size()&&!flag;++m)
for(int t=m+1;t<save.size()&&!flag;++t){
if((save[j]+save[k]+save[m]+save[t])%input==0){
cout<<"Yes"<<endl;
flag=true;
}
}
}
if(!flag)
cout<<"No"<<endl;
}
}
return 0;
}
矩阵行平移
#include <iostream>
using namespace std;
int main() {
int n,k,x;
int ans[110],cnt=0;
cin>>n>>k>>x;
int p=0;
int line[200][200];
for(int i=0;i<n;++i){
if(i%2!=0){
for(int j=0;j<n;++j){
cin>>line[i][j];
}
}else{
p=p%k+1;
for(int j=p;j<p+n;++j){
cin>>line[i][j];
}
for(int j=0;j<p;++j)line[i][j]=x;
}
}
for(int i=0;i<n;++i){
int sum=0;
for(int j=0;j<n;++j){
sum+=line[j][i];
}
ans[cnt++]=sum;
}
for(int i=0;i<cnt;++i){
if(i==0)cout<<ans[i];
else cout<<" "<<ans[i];
}
return 0;
}
岩洞施工
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N,min_num=1000,max_num=0,temp;
cin>>N;
for(int i=0;i<N;++i){
cin>>temp;
min_num=min(min_num,temp);
}
for(int i=0;i<N;++i){
cin>>temp;
max_num=max(max_num,temp);
}
if((min_num-max_num)<=0)cout<<"No "<<1-min_num+max_num<<endl;
else cout<<"Yes "<<min_num-max_num<<endl;
return 0;
}
性感素数
#include <iostream>
#include <algorithm>
using namespace std;
bool is_prime(int x){
if(x<=1)return false;
for(int i=2;i*i<=x;++i){
if(x%i==0)return false;
}
return true;
}
int main() {
int N;
cin>>N;
bool ans_s=is_prime(N-6);
bool ans_b=is_prime(N+6);
if(is_prime(N)&&(ans_s||ans_b)){
cout<<"Yes"<<endl;
if(ans_s)cout<<N-6;
else cout<<N+6;
}else{
for(int i=N+1;;++i){
ans_s=is_prime(i-6);
ans_b=is_prime(i+6);
if(is_prime(i)&&(ans_s||ans_b)){
cout<<"No"<<endl;
cout<<i;
return 0;
}
}
}
return 0;
}
校庆
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
string cmp(string a,string b){
if(a=="")
return b;
for(int i=6;i<=14;++i){
if(a[i]>b[i]) return b;
else if(b[i]>a[i]) return a;
}
return b;
}
int main() {
int N,M,cnt=0;
string old1="",old2="";
map<string,bool> people;
string temp;
cin>>N;
for(int i=0;i<N;++i){
cin>>temp;
people[temp]=true;
}
cin>>M;
for(int i=0;i<M;++i){
cin>>temp;
if(people[temp]){
old2=cmp(old2,temp);
cnt++;
}
old1=cmp(old1,temp);
}
if(cnt){
cout<<cnt<<endl<<old2;
}else{
cout<<cnt<<endl<<old1;
}
return 0;
}
网友评论