输入包含一行或多行,每行包含一个整数n。如果 n = 0 表示输入结束,否则n是一个skew数
可能有多组测试数据,对于每一个输入, 输出它的十进制表示。转换成十进制后的结果不超过 2^31-1 = 2147483647
10120 200000000000000000000000000000 10 1000000000000000000000000000000 11 100 11111000001110000101101102000 0
44 2147483646 3 2147483647 4 7 1041110737
题目xk*(2k+1-1)中的2k表示的是2的k次方。。。。还以为是2k连接成一个数
#include <iostream>
#include <cmath>
using namespace std;
int main(){
string str;
while(cin>>str && str!="0"){
int i=str.size()-1;
int sum=0;
while(i>=0){
string s=""; s+=str[i];
int m=stoi(s);
if(m>0)
sum+=m*(pow(2,(str.size()-i))-1);
--i;
}
cout<<sum<<endl;
}
return 0;
}
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
char ch[32];
while(cin >> ch){
int count=0;
for (int i = 0; i < strlen(ch)/2; i++) {
char temp = ch[i];
ch[i] = ch[strlen(ch) - 1 - i];
ch[strlen(ch) - 1 - i] = temp;
if(ch[i]!=0)
count++;
}
if(count==0)
break;
int a[32];
int total = 0;
for (int i = 0; i < strlen(ch); i++)
total += (pow(2, i + 1) - 1)*(ch[i] - '0');
cout << total << endl;
}
}
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
long long n;
while(cin >> n)
{
int sum=0, i=1, t;
while(n)
{
t = n % 10;
sum += t*(pow(2, i)-1);
n /= 10;
i++;
}
cout << sum << endl;
}
return 0;
} #include <stdio.h>
#include <string.h>
#include <math.h>
int main() {
char array[30];
int sum;
while (scanf("%s",array)!=EOF) {
sum=0;
if(strlen(array)==1&&array[0]=='0')
break;
for(int i=0;i<strlen(array);i++){
sum+=(array[i]-'0')*(pow(2,strlen(array)-i)-1);
}
printf("%d\n",sum);
}
return 0;
} def skew(n): s = 0 i=0 while n: i += 1 t = n % 10 n = n // 10 s += t * (2**i-1) return s while True: try: n = int(input()) if n == 0: break print(skew(n)) except: break
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(){
int binary[31];
for(int i=0; i<31; ++i){
binary[i]=pow(2, i+1)-1;
}
string str;
while(cin >> str && str != "0"){
int res = 0;
for(int i=str.size()-1, k=0; i>=0; --i, ++k){
res += (str[i] - '0') * binary[k];
}
cout << res << endl;
}
}
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
string str;
while (cin >> str) {
int skew = 0;
for (int i = 0, j = str.size(); i < str.size(); i++, j--) {
skew += (str[i] - '0') * (pow(2, j) - 1);
}
cout << skew << endl;
}
return 0;
} #include <bits/stdc++.h>
using namespace std;
string skew;
int main()
{
while (cin >> skew)
{
if (skew == "0")
break;
int sum = 0;
for (int i = 0; i < skew.length(); i++)
sum += (pow(2, skew.length() - i) - 1) * (skew[i] - '0');
cout << sum << endl;
}
return 0;
} #include<iostream>
#include<cmath>
using namespace std;
int main()
{
string str;
while(cin>>str)
{
if(str=="0") break;
int n=0;
for(int i=0;i<str.size();i++)
{
n+=(str[i]-'0')*(pow(2, str.size()-i)-1);
}
cout<<n<<endl;
}
} #include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
int main(){
string str;
while(cin>>str){
if(str == "0") break;
int len = str.size();
int index = 0;
int ans = 0;
while(index < len){
ans += (str[index] - '0') * (pow(2, len - index) - 1);
index++;
}
cout<<ans<<endl;
}
return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string skew;
while (cin >> skew)
{
reverse(skew.begin(), skew.end());
int res = 0;
for (int i = 0; i < skew.size(); ++i)
res += (skew[i]-'0') * ((2 << i) - 1);
cout << res << endl;
}
return 0;
}