平衡三进制1
Smiling & Weeping
---- 只要想起一生中后悔的事,
梅花便落满了南山。
题目链接:https://www.matiji.net/exam/dohomework/4183/3
题目:三进制计算机1
思路:不难,就是往前遍历,-1,0,1也就是代表本位
Talk is cheap , show me the code
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 inline int getnum(char c){ 5 if(c == '0') return 0; 6 else if(c == '1') return 1; 7 else return -1; 8 } 9 int main() 10 { 11 scanf("%d",&n); 12 for(int i = 1; i <= n; i++){ 13 char nums[100]; 14 scanf("%s",nums); 15 int len = strlen(nums) , num=0; 16 for(int j = 0; j < len; j++) 17 num = num*3 + getnum(nums[j]); 18 printf("%d\n",num); 19 } 20 return 0; 21 }
所谓无底深渊,下去,也是前程万丈
文章到此结束,我们下次再见ヾ(@^▽^@)ノ