以下相同代码,开启o2优化,就只能通过5个点,会把所有全都判成'lucky word',而关闭o2优化,能AC。这是为啥?
#include <stdio.h>
#include <string.h>
int sushu(int i){
int ss[25]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
for(int j=0;j<=25;j++){
if(i==ss[j]){
return 1;
}
}
return 0;
}
int main() {
char x[1000];
gets(x);
int n = strlen(x);
int alpha_count[1000] = {0};
for (int i = 0; i < n; i++) {
alpha_count[x[i]]++;
}
int min = 100, max = 0;
for (int i = 'a'; i <= 'z'; i++) {
if (alpha_count[i]) {
min = alpha_count[i] < min ? alpha_count[i] : min;
max = alpha_count[i] > max ? alpha_count[i] : max;
}
}
int ret = max-min;
printf("%s\n%d", sushu(ret)?"Lucky Word":"No Answer",sushu(ret)?ret:0);
return 0;
}