兔子的0分求救

题目总版

Sprunki_Rabbit @ 2024-09-16 17:38:11

WA

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    int list[26] = {};
    int prime[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};
    cin >> s;
    int maxn = 0,minn = 0;

    for(int i=0;i<s.size();i++)
        list[s[i]-'a']++;
    for(int i=0;i<26;i++)   
    {
        if(list[i] > maxn)
            maxn = list[i];
        if(list[i] < minn)
            minn = list[i];
    }
    int n = maxn - minn;
    for(int i=0;i<25;i++)
    {
        if(n == prime[i])
        {
            cout << "Lucky Word" << endl;
            cout << n;
            return 0;
        }
    }
    cout << "No Answer" << endl;
    cout << n;

    return 0;
}
求dalao指点

by Sprunki_Rabbit @ 2024-09-16 17:42:40

求调


by yinqf @ 2024-09-16 17:44:21

题号?


by Sprunki_Rabbit @ 2024-09-16 17:45:40

@yinqf P1125 [NOIP2008 提高组] 笨小猴


by Sprunki_Rabbit @ 2024-09-16 17:45:49

P1125 [NOIP2008 提高组] 笨小猴


by chenly8128 @ 2024-09-16 18:08:50

错误有3个:

  1. minn初始不能为0
  2. 没有考虑 list 中会有0的情况
  3. No answer情况下应该直接输出0

自己改改吧。


|