1.3.1(A+B)
1.3.2((A+B) imes C)
1.3.3((A+B)/C()整除())
1.3.4
1.3.5
(Scanf)缺少& 导致(WA)
#include <cstdio>
#include <iostream>
using namespace std;
int main( ){
double a,b,c;
scanf("%lf%lf",&a,&b);
c=a/b;
printf("%.9lf",c);
return 0;
}
http://noi.openjudge.cn/ch0103/05/
1.3.6
输出%可以使用printf(“%%”);
#include <cstdio>
#include <iostream>
using namespace std;
int main( ){
double a,b,c;
scanf("%lf%lf",&a,&b);
c=100*b/a;
printf("%.3lf%%",c);
//printf("")
return 0;
}
http://noi.openjudge.cn/ch0103/06/
1.3.9
对算数表达式的书写与输出
#include <cstdio>
#include <iostream>
using namespace std;
int main( ){
double r;
double const pi=3.14159;//(定义常数)
double d,area,length;
scanf("%lf",&r);
d=2*r;
area=pi*r*r;
length=2*pi*r;
printf("%.4lf %.4lf %.4lf",d,length,area);
return 0;
}
http://noi.openjudge.cn/ch0103/09/
1.3.11
注意:输出时小数尾部没有多余的0,可以用下面这种格式:
double x;
x = 1.33;
printf("%g", x);
源代码如下
#include<bits/stdc++.h>
#define Pi 3.1415926
using namespace std;
int main(){
double a,b;
cin>>a>>b;
while(a>=b)
a-=b;
printf("%g",a);
return 0;
}
http://noi.openjudge.cn/ch0103/11/
1.3.13
反向输出三位数(100—001)
AC1
#include <cstdio>
#include <iostream>
using namespace std;
int main( ){
int n;
int c,b,a;
scanf("%d",&n);
c=n%10;
n=(n-c)/10;
b=n%10;
n=(n-b)/10;
printf("%d%d%d",c,b,n);
return 0;
}
AC2
#include<bits/stdc++.h>
using namespace std;
int main( ){
int n;
cin>>n;
for(int i=1;i<=3;i++){
cout<<n%10;
n=n/10;
}
return 0;
}
WA
#include <cstdio>
#include <iostream>
using namespace std;
int main( ){
int n;
int c,b,a;
scanf("%d",&n);
c=n%10;
n=(n-c)/10;
b=n%10;
n=(n-b)/10;
a=c*100+10*b+n;
printf("%d",a);
return 0;
}
http://noi.openjudge.cn/ch0103/13/
1.3.15
WA 6分
#include <iostream>
#include <cstdio>
using namespace std;
int main( ){
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
int j;
int m;
m=(y/x)+1;
j=n-m;
printf("%d",j);
return 0;
}
AC
#include<bits/stdc++.h>
using namespace std;
int main(){
int y = 0;
int x = 0;
int n = 0;
scanf("%d %d %d",&n,&x,&y);
int eatapple = 0;
if(y%x>0)
eatapple = (y/x)+1;
else eatapple = y/x;
if(n>eatapple)
printf("%d",n-eatapple);
else if (eatapple==0)
printf("%d",n);
else
printf("%d",0);
return 0;
}
1.3.20
幂函数pow(2,n)
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
cout << (int)pow(2, n) << endl;
return 0;
}