zoukankan      html  css  js  c++  java
  • SDUSTOJ T1581 Average Number

    Average Number

    Time Limit: 1 Sec  Memory Limit: 128 M

    Description

    Please calculate the average number of the given n numbers without doing calculations of addition, multiplication, or division, or using any library fuction which is not in "stdio.h". It is guaranteed that the results are all integers and they are not less than 1 and not bigger than 100.

    Input

    The first line of the input contains a single integer T, indicating the number of the test cases, one per line.
    Each test case starts with an integer n(1 ≤ n ≤ 200), followed by n numbers to calculate the average number. All numbers are within the range of [1, 100].

    Output

    For each test case, output the average number, one per line.

    Sample Input

    17 46 93 49 70 66 69 20

    Sample Output

    59

    HINT

    If any character of "+", "*", "/" or any name of library fuction which is not in "stdio.h" appers in your code, you will get "Invalid Word" and your code will not be accepted.


    分析:这个题目不难,关键是思路,不能用加法,乘法,除法,那为什么没说不能用减法。所以这个题的关键就是把所有的运算都转化为减法。


    #include <stdio.h>
     
    int main()
    {
        int n,m,i,j;
        int temp,sum;
        double avr;
        scanf("%d",&n);
        for(i=1;i<=n;i=(i-(-1)))
        {
            scanf("%d",&m);
            for(j=1,sum=0;j<=m;j=(j-(-1)))
            {
                scanf("%d",&temp);
                sum = sum - (-temp);
            }
            for(avr=0;sum!=0;avr=(avr-(-1)))
            {
                sum = sum - m;
            }
            printf("%.0lf
    ",avr);
        }
        return 0;
    }


  • 相关阅读:
    Leetcode No.121
    Leetcode No.97 ***
    (描述需要改进) Leetcode No.71 **
    (描述需要改进)Leetcode No.68 **
    Leetcode No.72 ***
    【笔记】存储位置/修改表/字符集.【3(完结创建表)】
    redis 事件驱动模型解析
    redis 官网文档学习笔记 简单翻译
    redis 官网文档 sentinel 简单翻译 && 简单总结QA
    redis 学习笔记 总
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312815.html
Copyright © 2011-2022 走看看