1.4编程基础之逻辑表达式与条件分支
Portal:http://noi.openjudge.cn/ch0104/
这些题没什么好说的,直接上代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) int main() { int n; cin>>n; if (n>0)cout<<"positive"; if (n==0)cout<<"zero"; if (n<0)cout<<"negative"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) int main() { double n; cin>>n; printf("%.2lf",fabs(n)); return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) int main() { int n; cin>>n; if (n%2==1)cout<<"odd"; if (n%2==0)cout<<"even"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { char a; int n; scanf("%c",&a); n=a; if (n%2==1)cout<<"YES"; else cout<<"NO"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) int main() { int a,b; cin>>a>>b; if (a>b)cout<<'>'; if (a==b)cout<<'='; if (a<b)cout<<'<'; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n; cin>>n; if (99>=n&&n>=10) cout<<1; else cout<<0; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b; cin>>a>>b; if (a>=10||b>=20) cout<<1; else cout<<0; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n; cin>>n; if (n%3==0&&n%5==0) cout<<"YES"; else cout<<"NO"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n; cin>>n; if (n%3==0&&n%5==0&&n%7==0) cout<<"3 5 7"; else if (n%3==0&&n%5==0) cout<<"3 5"; else if (n%5==0&&n%7==0) cout<<"5 7"; else if (n%3==0&&n%7==0) cout<<"3 7"; else if (n%3==0) cout<<'3'; else if (n%5==0) cout<<'5'; else if (n%7==0) cout<<'7'; else cout<<'n'; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b; cin>>a>>b; if (a<60&&b>=60||a>=60&&b<60) cout<<'1'; else cout<<'0'; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n; cin>>n; if (n==1||n==3||n==5) cout<<"NO"; else cout<<"YES"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { double n; cin>>n; if (50+n/3.0<n/1.2) cout<<"Bike"; else if (50+n/3.0==n/1.2) cout<<"All"; else cout<<"Walk"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { double n; cin>>n; if(0<=n&&n<5) printf("%.3lf",-n+2.5); else if(5<=n&&n<10) printf("%.3lf",2-1.5*(n-3)*(n-3)); else if(10<=n&&n<20) printf("%.3lf",n/2-1.5); return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n,s; char a; cin>>n>>a; s=8; if(n>1000) if(n%500) s+=4*((n-1000)/500+1); else s+=4*(n-1000)/500; if (a=='y') s+=5; cout<<s; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int max(int a,int b) { if (a>=b) return a; else return b; } int main() { int a,b,c; cin>>a>>b>>c; cout<<max(max(a,b),c); return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b,c; cin>>a>>b>>c; if((a+b>c)&&(a+c>b)&&(b+c)>a) cout<<"yes";else cout<<"no"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a; cin>>a; if (a%4==0) if(a%100==0) { if(a%3200!=0 && a%400==0)cout<<'Y'; else cout<<'N'; } else cout<<'Y'; else cout<<'N'; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int x,y; cin>>x>>y; if(1>=x&&x>=-1&&1>=y&&y>=-1) cout<<"yes"; else cout<<"no"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b; char s; scanf("%d %d %c",&a,&b,&s); if (s=='+') cout<<a+b; else if (s=='-') cout<<a-b; else if (s=='*') cout<<a*b; else if (s=='/') if (b==0) cout<<"Divided by zero!"; else cout<<a/b; else cout<<"Invalid operator!"; return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<math.h> using namespace std; int main() { double a,b,c,d; scanf("%lf%lf%lf",&a,&b,&c); d=b*b-4*a*c; if(d<0) { if(b==0){ printf("x1=%.5lf+%.5lfi;",fabs(-b/(2*a)),(sqrt(-d))/(2*a)); printf("x2=%.5lf-%.5lfi",fabs(-b/(2*a)),(sqrt(-d))/(2*a)); } else { printf("x1=%.5lf+%.5lfi;",-b/(2*a),(sqrt(-d))/(2*a)); printf("x2=%.5lf-%.5lfi",-b/(2*a),(sqrt(-d))/(2*a)); } } else if(d==0)printf("x1=x2=%.5lf",-b/(2*a)); else printf("x1=%.5lf;x2=%.5lf",(-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)); return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int n,x,y,ans; cin>>n>>x>>y; ans=y/x; if(ans*x!=y) ans++; if(ans>n) cout<<0; else cout<<n-ans; return 0; }