hdu 短,hdu

來源:互聯網
上載者:User

hdu 短,hdu

短 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 172   Accepted Submission(s) : 7Font: Times New Roman | Verdana | Georgia Font Size: ← →Problem Description輸出[L, R]中能被9整除的數的個數 Input多組測試資料
每組測試資料包含兩個數L和R
所有資料都在int範圍內。 Output每組資料輸出一個整數,表示區間[L, R]中能被9整除的數的個數 Sample Input
1 91 10
Sample Output
11

/*題解:
    有點略坑的題,考慮完所有的情況再Wrong了一次的情況下A了。
注意點:
    輸入資料為int範圍內的整數,所以可以是負數,例如-18、-19 
    輸入資料不一定L<=R,所以先判斷大小並交換位置。(L<=R則不用交換) 
    0也可以被9整除
    【0,0】,【9,9】,【-9,-9】能被整除個數均為1
    提供幾組資料:
        【0,19】 3
        【9,18】 2
        【-18,-9】 2
        【-20,9】 4 
        【-18,-7】 2 
*/

#include<cstdio>#include<cmath>#include<stdlib.h>int main(){    int l,r,t;    while(scanf("%d %d",&l,&r)!=EOF)    {        if(l>r)//不交換會Output Limit Exceeded         {            t=l;            l=r;            r=t;        }        if(l==r)//情況一、l==r         {            if(l%9==0)            {                printf("1\n");            }            else printf("0\n");        }        else        {            if(l>0)//l>0,r>0             {                printf("%d\n",r/9-(l-1)/9);            }            else if(l==0)//l==0,r>0            {                printf("%d\n",r/9+1);            }            else if(l<0)            {                if(r==0)//l<0,r==0                 {                    printf("%d\n",abs(l/9)+1);                }                else if(r<0)//l<0,r<0                {                    printf("%d\n",abs(l/9)-(abs(r)-1)/9);                }                else if(r>0)//l<0,r>0                {                    printf("%d\n",r/9+abs(l/9)+1);                }            }        }    }    return 0;}






























聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.