markdown 在线制作ppt json校验和格式化工具

POJ 1702

  1 #include <iostream>
  2 #include <cmath>
  3 #define MAXN 100
  4 using namespace std;
  5 
  6 void fun(int num);
  7 void fun_1();
  8 
  9 int ans[MAXN];
 10 
 11 struct node
 12 {
 13     int ans[MAXN];
 14     int len;
 15     node()
 16     {
 17         memset(ans,0,sizeof(ans));
 18         len = 0;
 19     }
 20 };
 21 
 22 node _l;
 23 node _r;
 24 
 25 int main()
 26 {
 27     //freopen("acm.acm","r",stdin);
 28     int test;
 29     int i;
 30     int num;
 31 
 32     cin>>test;
 33     while(test --)
 34     {
 35         memset(_r.ans,0,sizeof(_r.ans));
 36         memset(_l.ans,0,sizeof(_l.ans));
 37         cin>>num;
 38         fun(num);
 39         fun_1();
 40         bool boo;
 41         int tem = 0;
 42         boo = false;
 43     //    int p = -1;
 44     //    bool ok = false;
 45         int index = 0;
 46         for(i = 0; i < MAXN; ++ i)
 47         {
 48             if(_l.ans[i] != 0)
 49             {
 50                 ans[index ++]  = pow((double)3,tem);
 51                 boo = true;
 52             }
 53             
 54             ++ tem;
 55         }
 56         if(boo)
 57         {
 58             for(i = 0; i < index-1; ++ i)
 59             {
 60                 cout<<ans[i]<<",";
 61             }
 62             cout<<ans[index-1]<<" ";
 63         }
 64         else
 65         {
 66             cout<<"empty ";
 67         }
 68         
 69 
 70 
 71         index = 0;
 72         boo = false;
 73         tem = 0;
 74         for(i = 0; i < MAXN; ++ i)
 75         {
 76             if(_r.ans[i] != 0)
 77             {
 78                 ans[index ++]  = pow((double)3,tem);
 79                 boo = true;
 80             }
 81             
 82             ++ tem;
 83         }
 84         if(boo)
 85         {
 86             for(i = 0; i < index-1; ++ i)
 87             {
 88                 cout<<ans[i]<<",";
 89             }
 90             cout<<ans[index-1];
 91         }
 92         cout<<endl;
 93     }
 94 }
 95 
 96 void fun(int num)
 97 {
 98     int i;
 99     int tem;
100     i = 0;
101     while(num)
102     {
103         _r.ans[i ++] = num%3;
104         num /= 3;
105     }
106     _r.len = i;
107 }
108 
109 void fun_1()
110 {
111     int i;
112     int c = 0;
113     for(i = 0; i < MAXN; ++ i)
114     {
115         _r.ans[i] += c;
116         if(_r.ans[i] == 2)
117         {
118             _r.ans[i] = 0;
119         //    _r.ans[i+1] += 1;
120             c = 1;
121             _l.ans[i] += 1;
122         }
123         else if(_r.ans[i] == 3)
124         {
125             _r.ans[i] = 0;
126         // _r.ans[i+1] += 1;
127             c = 1;
128         }
129         else
130         {
131             c = 0;
132         }
133         
134 
135     }
136 }

 

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

posted @ 2015-06-10 16:40  GavinHacker  阅读(160)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具