题解 | #游游的整数切割#
游游的整数切割
https://www.nowcoder.com/practice/c01b07fe9623425a806c85cdb6f0e0f7
#include <stdio.h> #include <string.h> int f(char*a){ int length = strlen(a); int n=0; for (int i=0;i<length-1;i++){ int left=a[i]-'0'; int right=a[length-1]-'0'; if((left%2==0&&right%2==0)||(left%2==1&&right%2==1)){ n++;} } return n; } int main() { char a[1000000]; int n; scanf("%s",a); n=f(a); printf("%d",n); return 0; }
求简化,这里直接判断个位了,免去相加