问题遇到的现象和发生背景
有多组输入,每组输入占一行
每行一串二进制数,长度 不少于 80,000,000。
如果对应的十进制数可以被3整除则输出yes,否则输出no;
问题相关代码,请勿粘贴截图
#include
#include<string.h>
int count(char, int, int);//逐位取余函数
using namespace std;
int main()
{
char a[20000];
while (cin >> a)
{
int n = 0, s = 0, i = 0; n = strlen(a);
// cout<<n<<endl;
for (i = 0; i < n; i++)
s += count(a[i], i, n - 1);
if (s % 3 == 0)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
int count(char a, int i, int n)
{
int b = 'a' - '0', s = 1;
if (b == 0)
return 0;
else
for (i; i < n; i++)
s *= 2;
return s;
}
运行结果及报错内容
runtime error(非法内存访问,分段错误)
我的解答思路和尝试过的方法
二维数组也没成功;
我想要达到的结果
如何实现输入超过80,000,000的字符串