2011/07/30

Codeforces Unknown Language Round #3 Report

It's special contest! Congratulation to Codeforces because they make 100th contest!

[Rule]
We can submit your code using only one language. This language is a secret and will be announced only when the contest begins!
-> The language we can use is Pike7.8. The language isn't rank in TIOBE.

[Report]
Start, I get compiler. I use Ubuntu Linux 11.04, so I can install with next command.

sudo apt-get install pike7.8

And read tutorials(here). I can join this contest only two hour, so I think it's good I can get two accepted.

A: Use read function and cast. I got accepted 0:43.

  • I couldn't find how to input integer. So, read and cast.
  • Fortunately, if we cast string to integer, it works as C's atoi function.

C: Use string. I got accepted  1:54.

  • We can get n-th character of string s with s[n] (0-offset). However, it's int.
  • So,  s[n]-'0' means the number s[n] of int.

Result, Penalty=177, Standings=155/805.

I expect to hold next Unknown language round!

These source is written with Pike7.8 .
If you want to compile and test , please next command.


pike7.8 source.pike


[A]

int main(){
  int n,k,m;
  n=(int)Stdio.stdin->read(2);
  k=(int)Stdio.stdin->read(3);
  m=(int)Stdio.stdin->read(3);
  if(n*n>k*m*m) write("NO\n");
  else{
    if(m==n) write("YES\n");
    else if(k<4) write("NO\n");
    else write("YES\n");
  }  
  return 0;
}

[C]

int main(){
  string A=Stdio.stdin->gets();
  string B=Stdio.stdin->gets();
  string C;
  int alen,blen;
  int i,j,k=0,tmp;
 
  alen=strlen(A);
  blen=strlen(B);
  for(i=alen-1,j=blen-1;i>=0 || j>=0;i--,j--){
    if(i<0){
     tmp=B[j]-'0'+k;
      k=tmp/10;
      tmp%=10;
    }else if(j<0){
      tmp=A[i]-'0'+k;
      k=tmp/10;
      tmp%=10;
    }else{
      tmp=A[i]-'0'+B[j]-'0'+k;
      k=tmp/10;
      tmp%=10;
    }
    if(i==alen-1 && j==blen-1) C=sprintf("%d",tmp);
    else C+=sprintf("%d",tmp);
  }
  if(k==1) C+=sprintf("%d",1);
  for(i=strlen(C)-1;i>=0;i--) write("%c",C[i]);
  write("\n");
  return 0;
}

0 件のコメント:

コメントを投稿