希望更丰富的展现?使用[Markdown](https://www.luogu.org/wiki/show?name=%E5%B8%AE%E5%8A%A9%EF%BC%9Amarkdown)
by forlight @ 2019-07-14 11:44:09
```cpp
for(int i=0;i<7;i++)
num=(a[i]-64);
for(int j=0;j<7;j++)
ans=(b[j]-64);
```
没看题目,但感觉这里有问题
是不是应该改成+=或者别的?
by forlight @ 2019-07-14 11:45:46
@[forlight](/space/show?uid=97238)
的确是这边出问题,题目是累乘,他直接赋值了。
还有就是题目的字符串长度是不固定的,应该用一个strlen函数限制for循环的循环次数,不然乘一个'\0'就啥都没了
by zhubaolin @ 2019-07-14 11:51:49
题目要求为 **“一个长度为1到6的大写字母串”**,所以其长度不一定为6。而且长度为6时,你的循环:
```c
for(int i=0;i<7;i++)
num=(a[i]-64);
```
其中 i 从 0 ~ 6,超出了字母串长度。
所以这里应用一个获取字符串长度的函数:
> strlen()
```c
#include <stdio.h>
#include <string.h> //strlen()
int main(void)
{
const int MOD = 47;
char comet[10]; //彗星
char group[10]; //小组
int comet_product = 1; //彗星转换成的数字
int group_product = 1; //小组转换成的数字
unsigned i; //strlen()的返回值是unsigned类型
scanf("%s", comet);
scanf("%s", group);
for (i = 0; i < strlen(comet); i++)
comet_product *= (int)(comet[i] - 'A' + 1);
for (i = 0; i < strlen(group); i++)
group_product *= (int)(group[i] - 'A' + 1);
if (comet_product % MOD == group_product % MOD)
printf("GO\n");
else
printf("STAY\n");
return 0;
}
```
其实这道题保险一点应该声明 long long int 类型,但数据强度较弱。
by Turmoil @ 2019-07-14 12:03:05