• Openjudge 1.4 逻辑表达式与条件分支


    1.4.1

    a==0!!!!!!!!!!
    判断等于== 赋值符号=(注意!!!!)
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main( ){
    	int a=0;
    	scanf("%d",&a);
    	if(a>0) {
    		printf("positive");
    	}
    	if(a==0){
    		printf("zero");
    	}
    	if(a<0){
    		printf("negative");
    	}
    	return 0;} 
    

    http://noi.openjudge.cn/ch0104/01/

    1.4.4

    读取单个字符 getchar() 速度更快
    存放的是字符对应的ASCII码

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	char ch;
    	ch = getchar();
    	if (ch%2 == 0) cout << "NO" << endl;
    	else cout << "YES" << endl;
    	return 0;
      }
    
    

    1.4.14

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
        int weight,cost=8;
        char quick;
    scanf("%d%s",&weight,&quick);
        if (weight > 1000) {
            weight -= 1000;
            cost += weight/500*4;
            if (weight%500 != 0) cost += 4;
        }
        if (quick == 'y') cost += 5;
        printf("%d",cost);
        return 0;
    }
    
    //字符串所对应的类型
    //{%d int  %f float   %lf double %s char[]} %c单个字符
    

    1.4.18

    #include <iostream>
    #include <cstdio>#include <cmath>using namespace std;int main(){
        int a,b,c;
        char k;
        scanf("%d %d",&a,&b);
        //scanf("",&b);
        scanf("%s",&k); 
        printf(" %d/ %d/",a,b);
        if(b==0&&k=='/'){
        	printf("Divided by zero!");
    		return 0;
    	}
    	if(k!='+'&&k!='-'&&k!='/'&&k!='*'){
    		printf("Invalid operator!");
    		return 0;
    	}
        if(k=='+'){
        	c=a+b;
    		printf("%d",c);
        	return 0;
    	};
    	if(k=='-'){
    		c=a-b;		
    		printf("%d",c);
        	return 0;
    	}
    	if(k=='*'){
    		c=a*b;		
    		printf("%d",c);
        	return 0;
    	}
    	if(k=='/'){
    		c=a/b;		
    		printf("%d",c);
        	return 0;
    	}}
    
    要做就做南波万
  • 相关阅读:
    python笔记1
    git笔记
    手撸一个简陋直播系统
    spring-boot学习笔记1
    设计模式1--简单工厂模式
    网联:第一章:浏览器生成消息
    php线上预览日志--4.websocket客户端
    php线上预览日志--3.websocket服务部署
    php线上预览日志--2.谷歌插件开发
    php线上预览日志--1.概述
  • 原文地址:https://www.cnblogs.com/liuziwen0224/p/11991576.html
Copyright © 2020-2023  润新知