洛谷 P2415 集合求和 血的教训
作者:
星和彦
,
2022-03-19 12:06:45
,
所有人可见
,
阅读 187
20 分代码
#include<bits/stdc++.h>
using namespace std;
//dp[]i
unsigned long long dp[1100];
unsigned long long a[1100] , num;
int main(){
char s;
while( cin >> s ){
if( s == EOF ) break;
a[ ++ num ] = s - '0';
}
unsigned long long p = 1;
for(int i = 1 ; i <= num ; i ++ ){
dp[i] = dp[i - 1] * 2 + p * a[i] ;
p *= 2;
//cout << i <<" " << dp[i] << endl;
}
cout << dp[num];
}
100 分代码
#include<bits/stdc++.h>
using namespace std;
//dp[]i
unsigned long long dp[1100];
unsigned long long a[1100] , num;
int main(){
int s;
while( cin >> s ){
//if( s == EOF ) break;
a[ ++ num ] = s;
}
unsigned long long p = 1;
for(int i = 1 ; i <= num ; i ++ ){
dp[i] = dp[i - 1] * 2 + p * a[i] ;
p *= 2;
//cout << i <<" " << dp[i] << endl;
}
cout << dp[num];
}
数字超过一位注意char只能读一个