zoukankan      html  css  js  c++  java
  • 1063 弟弟的作业

    // Test1063-弟弟的作业.cpp: 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <stdlib.h>
    
    
    int main()
    {
        int result = 0;
        while (1)
        {
            char list[12] = {};
            scanf_s("%s", list, 10);
            if (list[1] =='')
                break;
            int middle = 0;
            int sumpos = 0;
            int length = 0;
            int a, b, temp_sum,sum = 0;
    
    
            for (int i = 0;i<10; i++)
            {
                if ((list[i] == '+') || (list[i] == '-'))
                    middle = i;
                if (list[i] == '=')
                    sumpos = i;
                if (list[i] == '')
                    length = i;
            }
            if (list[sumpos + 1] == '?')
                continue;
    
    
            if((middle-0)==2)
            {
                //printf("%d %d ", atoi(&list[0]), atoi(&list[1]));
                //a= atoi(&list[0])*10+atoi(&list[1]);
                a = atoi(&list[0]);
    
            }else
                a= atoi(&list[0]);
    
            if ((sumpos - middle - 1) == 2)
            {
                //b = atoi(&list[middle + 1]) * 10 + atoi(&list[middle+2]);
                b = atoi(&list[middle + 1]);
            }
            else
                b = atoi(&list[middle + 1]);
    
            if ((length - sumpos - 1) == 3)
                //sum = atoi(&list[sumpos + 1]) * 100 + atoi(&list[sumpos + 2]) * 10 + atoi(&list[sumpos + 3]);
                sum = atoi(&list[sumpos + 1]);
            else if ((length - sumpos - 1) == 2)
                //sum = atoi(&list[sumpos + 1]) * 10 + atoi(&list[sumpos + 2]);
                sum = atoi(&list[sumpos + 1]);
            else
                sum = atoi(&list[sumpos + 1]);
    
    
    
            if (list[middle] == '+')
                temp_sum = a + b;
            if (list[middle] == '-')
                temp_sum = a - b;
            if  (temp_sum== sum)
                result++;
            printf("%s
    ", list);
    
    
        }
        printf("%d
    ", result);
    
    
    
        //while ((c = getchar()) != EOF)
        //{
        //    putchar(c);
        //}
    
        return 0;
    }
    1 1+2=3
    2 3-1=5
    3 6+7=13
    4 99-0=5 99-0=99
    6 0
    7 3
    8 请按任意键继续. . .

    万事走心 精益求美


  • 相关阅读:
    字体图标
    HBase Shell 常用命令
    Centos7 KVM日常运维
    Centos7 KVM安装部署
    Centos7安装Puppet自动运维
    Centos7安装ansible自动运维
    H3C巡检基本命令
    组播学习
    Centos7下使用LVM给系统硬盘扩容
    python 类中方法总结 --- 实例方法、类方法、静态方法
  • 原文地址:https://www.cnblogs.com/kongchung/p/9330629.html
Copyright © 2011-2022 走看看