2014年10月2日 星期四

TIOJ 1026 . 惡猿果實

轉成二進位後弄弄看

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int int64;
int main()
{
 int arr[100];
 int cnt[100];
 int64 c;scanf("%lld", &c);
 int lx =0; while(c){
  arr[lx++] = c&1;
  c>>=1;
 }
 for(int ll = 0;ll < lx;ll++){
  cnt[ll] = 1;
  if(arr[ll] == 0)
   cnt[ll-1] = -1;
 }
 printf("%d\n", lx);
 for(int yy = 0;yy < lx;yy++)
  printf("%c", (cnt[yy] == 1) ? '+' : '-' );
 printf("\n");
 return 0;
}

沒有留言:

張貼留言