CF1567C
Carrying Conundrum
思维题。
实质上是做了一个奇偶数位分开的加法运算,那么把就数位组成的数单独抽成两个数
时间复杂度
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll T,ans,n,o,e;
ll buf[22];ll len=-1;
inline ll read() {
ll ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-f;ch=getchar();}
while(ch>='0'&&ch<='9') {ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
return ret*f;
}
void write(ll x) {
static char buf[22];static ll len=-1;
if(x>=0) {
do{buf[++len]=x%10+48;x/=10;}while(x);
}
else {
putchar('-');
do{buf[++len]=-(x%10)+48;x/=10;}while(x);
}
while(len>=0) putchar(buf[len--]);
}
void writeln(ll x) {
write(x);putchar('\n');
}
int main() {
T=read();
while(T--) {
n=read();e=0;o=0;
memset(buf,0,sizeof(buf));
if(n>=0) {
do{buf[++len]=n%10;n/=10;}while(n);
}
while(len>=0) {
if(len&1) {
o*=10;o+=buf[len];len--;
}
else {
e*=10;e+=buf[len];len--;
}
}
// printf("o=%lld e=%lld\n",o,e);
ans=(o+1)*(e+1)-2;
writeln(ans);
}
return 0;
}