Esco27's blog

By Esco27, history, 4 weeks ago, In English,

Your text to link here...

#include <iostream>
#include <cmath> 
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >>n;

    int flag=0;
    int t;

    for (int i=0;i<n;i++)
    {
        cin >>t;
        if (t%2==0)
        {
            cout<<t/2<<'\n';
        }
        else
        {
            if (flag==0)
            {
                cout<<ceil((double)t/2)<<'\n';
                flag=1;    
            }
            else
            {
                cout<<floor((double)t/2)<<'\n';
                flag=0;
            }

        }
    }
    return  0;
}
 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Esco27 (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

It seems like the checker does not accept "-0" instead of "0"...

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you elaborate a bit. I do not get when the code produces "-0" instead of "0".

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      ceil(-1/2.)
      
      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        But why is there -0 and 0. Should not both be the same, that is zero? Are there other functions besides ceil that have the same effect?

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          ceil returns a floating point number, and those have both. You should cast it to an int.