intmain(){int N,n,i,a,A,b,B,c,C,flag;scanf("%d",&N);for(i=0;i<N;i++){scanf("%d",&n);
A = B = C = flag =0;for(a=0;a<=n/3;a++){for(b=0;b<=n/5;b++){for(c=0;c<=n/7;c++){int sum = a*3+b*5+c*7;if(sum==n){
flag++;
A = a;
B = b;
C = c;}if(flag!=0){
a = b = c = n;}}}}if(A!=0||B!=0||C!=0){printf("%d %d %d\n",A,B,C);}else{printf("-1\n");}}return0;}
#include<stdio.h>#include<algorithm>intmain(void){longlongint t, n, k, sum;scanf("%lld",&t);longlongint a[200000];longlongint b[1000];int i,j;for(i=0;i<t;i++){
sum =0;scanf("%lld %lld",&n,&k);for(j=0;j<n;j++){scanf("%lld",&a[j]);}
std::sort(a,a+n);
sum = a[n-1];for(j=0;j<k;j++){
sum += a[n-j-2];}if(!k){
b[i]= sum - a[0];}else{
b[i]= sum;}}for(i=0;i<t;i++){printf("%lld\n",b[i]);}return0;}
#include<stdio.h>intswap(int n1,int n2){int sum =0;while(n1 !=0){
sum += n1%n2;
n1 /= n2;}return sum;}intmain(){int n,num;while(1){scanf("%d",&n);if(n ==0){break;}
num = n;int ten =swap(n,10);int twelve =swap(n,12);int sixteen =swap(n,16);if(twelve == sixteen && ten == twelve){printf("%d is a Sky Number.\n",num);}else{printf("%d is not a Sky Number.\n",num);}}return0;}
真值表如下 由上表知,若要使((A ^ C) & (B ^ C))最小,则只需 C = A & B ,若C = 0,则输出1,反之输出C。
#include<stdio.h>intmain(){int n;scanf("%d",&n);longlong a[1000][2];for(int i =0; i < n; i++){scanf("%lld%lld",&a[i][0],&a[i][1]);}for(int i =0; i < n; i++){longlongint c = a[i][0]& a[i][1];if(!c)printf("1\n");elseprintf("%lld\n", c);}return0;}