2 solutions

  • 1
    @ 2024-3-25 11:32:00

    #include #include

    using namespace std;

    string s; int num[256]; //num[i]描述字符i的出现次数 int n;

    bool isPrime(int n){ if (n<2) return 0; for (int i=2;i*i<=n;i++) if (n%i==0) return 0; return 1; }

    int main(){ cin >> s; for (int i=0;i<=s.length()-1;i++) num[ s[i] ]++;

    int maxn = -1e9, minn = 1e9;
    for (int i='a';i<='z';i++)
    	if (num[i]!=0)
    	{
    		maxn = max(maxn, num[i]);
    		minn = min(minn, num[i]);
    	}  
    
    if ( isPrime(maxn-minn) )
    	printf("Lucky Word\n%d\n",maxn-minn);
    
    else
    	printf("No Answer\n%d\n",0);
    

    }

    • 0
      @ 2024-3-25 11:31:47

      #include #include #include using namespace std; int main(){ char a[110]; int ans[26] = {0}; int l,mmax,mmin,delta; scanf("%s",a); l = strlen (a); for(int i =0;i < l;i++) ans[a[i]-'a']++; mmax = 0; mmin =10000; for(int i=0;i <26;i++){ if(ans[i]> mmax) mmax = ans[i]; if(ans[i] != 0 && ans[i] < mmin) mmin =ans[i]; } delta = mmax - mmin; if(delta == 0|| delta == 1){ printf("No Answer\n0\n"); return 0; } for (int h = 2;h*h <= delta;h++) if(delta % h == 0){ printf("No Answer\n0\n"); return 0; } printf("Lucky Word\n%d\n", mmax - mmin); return 0; }

      • 1

      Information

      ID
      125
      Time
      1000ms
      Memory
      125MiB
      Difficulty
      2
      Tags
      # Submissions
      57
      Accepted
      36
      Uploaded By