hdu_2008_數值統計

http://acm.hdu.edu.cn/showproblem.php?pid=2008

數值統計

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22191    Accepted Submission(s): 11726


Problem Description
統計給定的n個數中,負數、零和正數的個數。
 

Input
輸入數據有多組,每組佔一行,每行的第一個數是整數n(n<100),表示需要統計的數值的個數,然後是n個實數;如果n=0,則表示輸入結束,該行不做處理。
 

Output
對於每組輸入數據,輸出一行a,b和c,分別表示給定的數據中負數、零和正數的個數。
 

Sample Input
6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0
 

Sample Output
1 2 3 0 0 5
        1. #include<iostream>
        2. using namespace std;
        3. int main()
        4. {
        5. int n,a,b,c;
        6. double inn;
        7. while(cin>>n&&n!=0)
        8. {
        9. a=0;b=0;c=0;
        10. while(n--)
        11. {
        12. cin>>inn;
        13. if(inn<0)
        14. a++;
        15. else if(inn==0)
        16. b++;
        17. else
        18. c++;
        19. }
        20. cout<<a<<" "<<b<<" "<<c<<endl;
        21. }
        22. return 0;
        23. }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章