9.15+9.16 刷题记录

#include
#include
#include
#include
using namespace std;
int main(){
double sum;
int n,x[10000],y[10000];
while(scanf("%d",&n)!=EOF){
if (n==0) {
break;
}
sum=0;
scanf("%d %d",&x[0],&y[0]);
for (int i=1; i scanf("%d %d",&x[i],&y[i]);
sum+=x[i-1]*y[i]-x[i]*y[i-1];
}
sum+=x[n-1]*y[0]-x[0]*y[n-1];
printf("%.1lf\n",sum/2.0);

}

return 0;

}

double类型 !!!!
#include
#include
#include
#include
using namespace std;
int main(){
int n;
double x[10000],count=0;
scanf("%d",&n);
while(n–){
for (int i=0;i<3;i++) {
scanf("%lf",&x[i]);
}
sort(x, x+3);
if ((x[0]+x[1]>x[2])&&(x[2]-x[0] printf(“YES\n”);
}
else{
printf(“NO\n”);
}

}

return 0;

}

#include
#include
#include
#include
using namespace std;
int main(){
int n,a,b,sum;
scanf("%d",&n);
while(n–){
sum=0;
scanf("%d %d",&a,&b);
for (int i=1; i if (a%i==0) {
sum+=i;
}
}

    if (sum==b) {
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }


}

return 0;

}

爬楼梯! 斐波那契数列!!!!

#include
#include
#include
#include
using namespace std;
int main(){
int a[49]={0,0,1,2};
int n,m;
scanf("%d",&n);
while (n–) {
scanf("%d",&m);
for (int i=4; i<41; i++) {// 41!!!!
a[i]=a[i-1]+a[i-2];
}
printf("%d\n",a[m]);
}

return 0;

}

密码

#include
#include
#include
#include
using namespace std;
int main(){
int n,lenth;
char a[1000];
scanf("%d",&n);
while (n–) {
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
scanf("%s",a);
lenth=strlen(a);
if (lenth>=8&&lenth<=16) {
for (int i=0; i if (a[i]>=‘A’&&a[i]<=‘Z’) {///!!! 单引号
sum1++;
}
else if (a[i]>=‘a’&&a[i]<=‘z’) {
sum2++;
}
else if (a[i]>=‘0’&&a[i]<=‘9’) {
sum3++;
}
else
sum4++;
}
if (sum1sum2sum3!=0||sum1sum2sum4!=0||sum2sum3sum4!=0||sum1sum3sum4!=0) {
printf(“YES\n”);
}
else printf(“NO\n”);
}
else printf(“NO\n”);
}

return 0;

}

我是一只小蜜蜂 精度问题longlong ”%lld“

#include 
#include 
#include 
#include 
using namespace std;
int main(){
   int n;
   long long a,b;
    scanf("%d",&n);
    while (n--) {
        long long x[1000]={0,1,2};
        scanf("%lld %lld",&a,&b);
        long long s=b-a;
        for (int i=3; i<=s; i++) {
            x[i]=x[i-1]+x[i-2];
        }
        printf("%lld\n",x[s]);
    }
    return 0;
}
#include 
#include 
#include 
#include 
using namespace std;
int main(){
    int m;
    int n;
    double sum;
    scanf("%d",&m);
    while (m--) {
        scanf("%d",&n);
         sum=0.0;
        for (int i=1; i<=n;i++) {
            sum+=pow(-1, i+1)*(1.0/i);//陷阱:1.0不能写1
        }
        printf("%.2lf\n",sum);
    }
    
    return 0;
}

你可能感兴趣的:(acm)