Sunday, April 02, 2017

UVA Solution Prime words (10924)

  10924 Prime Words  UVA ONLINE JUDGE

#include<stdio.h>
#include<string.h>
#include<math.h>
char str[5000000];
int main()
{

    while(scanf("%s",str)!=EOF)
    {


    int a,b,c,d,e;
    a=strlen(str);
    for(c=0;c<a;c++)
    {
        if(str[c]>='a' && str[c]<='z')
        {
            str[c]=str[c]-96;
        }
       else if(str[c]>='A' && str[c]<='Z')
        {
            str[c]=str[c]-38;
        }
    }
    long long int result=0;
    for(c=0;c<a;c++)
    {
       result+=str[c];
    }

      int nil,bis=0;
      for(nil=1;nil<=sqrt(result);nil++)
      {

          if(result%nil==0)
          {
              bis++;
          }
      }
      if(bis==1)
      {
          printf("It is a prime word.\n");
      }
      else
        printf("It is not a prime word.\n");



}
return 0;
}

No comments:

Post a Comment