2011/07/09

Codeforces Beta Round #77(Div.2) report

There is a recorder ensemble concert immediately before, and after I performs to it, took part in the contest. I thought I shouldn't take part in it. So, the result isn't so good.

I started to solve problem A, however, I can't read the problem because network error. I thought I'll stop to join this, but I can read at 0:03. I solved it at 0:08.

Problem B. It has something hard to me. So, I solved at 1:50. I spent too much time! However, I thought I couldn't solve Problem C,D or E, because I couldn't understand the problems' mean.

487/1121,Score=486.Problems are here.

A.

#include<stdio.h>
#include<string.h>

int main(void){
  char str[128];
  int count=1;
  int i,j;
  scanf("%s",str);
  for(i=1;i<strlen(str);i++){
    if(str[i]==str[i-1]){
      count++;
    }else{
      count=1;
    }
    if(count>=7){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}

B.(Wrong answer)

#include<stdio.h>
#include<math.h>
#include<string.h>

typedef unsigned int u_int;

int main(void){
  u_int i,j,k,keta,c4=0,c7=0,forward;
  char num[16];
  scanf("%s",num);
  keta=strlen(num);

  if(keta%2==1){
    keta++;
    for(i=0;i<keta/2;i++) putchar('4');
    for(i=0;i<keta/2;i++) putchar('7');
    putchar('\n');
    return 0;
  }

  for(i=0;i<strlen(num);i++){
    //printf("for at num[%u]=%c \n",i,num[i]);
    if(num[i]=='4'){
      c4++;
      if(c4>keta/2){
num[i]='7';
c4--;
c7++;
      }
      continue;
    }else if(num[i]=='7'){
      c7++;
      if(c7>keta/2){
for(j=i;j>=0;j--){
 if(j==0){
   keta+=2;
   for(k=0;k<keta/2;k++) putchar('4');
   for(k=0;k<keta/2;k++) putchar('7');
   putchar('\n');
   return 0;
 }
 if(num[j]=='4'){
   num[j]='7';
   c4--;
   c7++;
   break;
 }else if(num[j]=='7'){
   num[j]='4';
   c4++;
   c7--;
 }
}
      }
      //puts("continue at7");
      continue;
    }
    if(num[i]<='3'){
      for(j=0;j<i;j++) putchar(num[j]);
      for(j=0;j<keta/2-c4;j++) putchar('4');
      for(j=0;j<keta/2-c7;j++) putchar('7');
      putchar('\n');
      return 0;
    }else if(num[i]<='6'){
      num[i]='7';
      c7++;
      if(c7>keta/2){
for(j=i;j>=0;j--){
 if(j==0){
   keta+=2;
   for(k=0;k<keta/2;k++) putchar('4');
   for(k=0;k<keta/2;k++) putchar('7');
   putchar('\n');
   return 0;
 }
 if(num[j]=='4'){
   num[j]='7';
   c4--;
   c7++;
   break;
 }else if(num[j]=='7'){
   num[j]='4';
   c4++;
   c7--;
 }
}
      }
      for(j=0;j<=i;j++) putchar(num[j]);
      for(j=0;j<keta/2-c4;j++) putchar('4');
      for(j=0;j<keta/2-c7;j++) putchar('7');
      putchar('\n');
      return 0;
    }else{
      for(j=i;j>=0;j--){
if(j==0){
 keta+=2;
 for(k=0;k<keta/2;k++) putchar('4');
 for(k=0;k<keta/2;k++) putchar('7');
 putchar('\n');
 return 0;
}
if(num[j]=='4'){
 num[j]='7';
 c4--;
 c7++;
 break;
}else if(num[j]=='7'){
 num[j]='4';
 c4++;
 c7--;
}
      }
      for(j=0;j<i;j++) putchar(num[j]);
      putchar('4');
      c4++;
      for(j=0;j<keta/2-c4;j++) putchar('4');
      for(j=0;j<keta/2-c7;j++) putchar('7');
      putchar('\n');
      return 0;
    }
  }
  puts(num);
  return 0;
}

0 件のコメント:

コメントを投稿