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 请按任意键继续. . .

    万事走心 精益求美


  • 相关阅读:
    一个很吊的swing循环生成窗口。
    hbase操作的问题
    hadoop+hbase
    linux故障救援
    管道命令xargs
    hadoop浅尝 hadoop与hbase交互
    linux源代码阅读笔记 free_page_tables()分析
    词法分析器flex的使用
    每天一个Linux命令(1): find
    梯度下降
  • 原文地址:https://www.cnblogs.com/kongchung/p/9330629.html
Copyright © 2011-2022 走看看