ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1025. Democracy in Danger

why i have 2 WA already ?
Posted by Pavel Martinov [USURT] 24 Apr 2005 20:06
Plz help me, i not understand why i have WA.

#include <stdio.h>

int main()
{
  int i,j=0,tmp,real;
  int K;
  int wantnum=0;
  int grp[101];

  scanf("%d",&K);
  for(i=0; i<K; i++)
  {
    scanf("%d",&tmp);
    if((tmp%2 == 0)) continue;
    grp[j] = tmp; j++;
  }
  real=j;

  for(i=0; i<K; i++)
    for(j=0; j<K-i; j++)
      if(grp[j] > grp[j+1])
      {
        tmp=grp[j];
        grp[j]=grp[j+1];
        grp[j+1]=tmp;
      }
  for(i=0; i<real/2+1; i++)
    wantnum += grp[i]/2+1;
  printf("%d",wantnum);
  return 0;
}
Re: why i have 2 WA already ?
Posted by AgainReg 5 Sep 2005 02:05
your bubble sort is not working right.
add -1 on the second for check

for(i=0; i<K; i++)
for(j=0; j<K-i - 1; j++)
if(grp[j] > grp[j+1])
{
tmp=grp[j];
grp[j]=grp[j+1];
grp[j+1]=tmp;
}

sorry for my english :P
Pavel Martinov [USURT] wrote 24 April 2005 20:06
Plz help me, i not understand why i have WA.

#include <stdio.h>

int main()
{
  int i,j=0,tmp,real;
  int K;
  int wantnum=0;
  int grp[101];

  scanf("%d",&K);
  for(i=0; i<K; i++)
  {
    scanf("%d",&tmp);
    if((tmp%2 == 0)) continue;
    grp[j] = tmp; j++;
  }
  real=j;

  for(i=0; i<K; i++)
    for(j=0; j<K-i; j++)
      if(grp[j] > grp[j+1])
      {
        tmp=grp[j];
        grp[j]=grp[j+1];
        grp[j+1]=tmp;
      }
  for(i=0; i<real/2+1; i++)
    wantnum += grp[i]/2+1;
  printf("%d",wantnum);
  return 0;
}
Pavel Martinov [USURT] wrote 24 April 2005 20:06
Plz help me, i not understand why i have WA.

#include <stdio.h>

int main()
{
  int i,j=0,tmp,real;
  int K;
  int wantnum=0;
  int grp[101];

  scanf("%d",&K);
  for(i=0; i<K; i++)
  {
    scanf("%d",&tmp);
    if((tmp%2 == 0)) continue;
    grp[j] = tmp; j++;
  }
  real=j;

  for(i=0; i<K; i++)
    for(j=0; j<K-i; j++)
      if(grp[j] > grp[j+1])
      {
        tmp=grp[j];
        grp[j]=grp[j+1];
        grp[j+1]=tmp;
      }
  for(i=0; i<real/2+1; i++)
    wantnum += grp[i]/2+1;
  printf("%d",wantnum);
  return 0;
}