# Perfect Square String

Given a String str and the task is to check sum of ASCII value of all characters is a perfect square or not.

Examples :

```Input : ddddddddddddddddddddddddd
Output : Yes

Input : GeeksForGeeks
Output : No
```

## Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.

Algorithm

• Calculate the string length
• Calculate sum of ASCII value of all characters
• Take the square root of the number sum and store it into variable squareRoot
• Take floor value of the squareRoot and subtract from squareRoot
• If the difference of floor value of squareRoot and squareRoot is 0 then print “Yes” otherwise “No”

Below is the implementation of the above approach :

## C++

 `// C++ program to find if string is a ` `// perfect square or not. ` `#include ` `using` `namespace` `std; ` ` `  `bool` `isPerfectSquareString(string str) ` `{ ` `    ``int` `sum = 0; ` `     `  `    ``// calculating the length of ` `    ``// the string ` `    ``int` `len = str.length(); ` `     `  `    ``// calculating the ASCII value ` `    ``// of the string ` `    ``for` `(``int` `i = 0; i < len; i++) ` `        ``sum += (``int``)str[i]; ` `     `  `    ``// Find floating point value of ` `    ``// square root of x. ` `    ``long` `double` `squareRoot = ``sqrt``(sum); ` `     `  `    ``// If square root is an integer ` `    ``return` `((squareRoot -  ` `             ``floor``(squareRoot)) == 0); ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``string str = ``"d"``; ` `     `  `    ``if` `(isPerfectSquareString(str)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` `} `

## Java

 `// Java program to find if string ` `// is a perfect square or not. ` `import` `java.io.*; ` ` `  `class` `GFG { ` `     `  `    ``static` `boolean` `isPerfectSquareString(String str) ` `    ``{ ` `        ``int` `sum = ``0``; ` `         `  `        ``// calculating the length ` `        ``// of the string ` `        ``int` `len = str.length(); ` `         `  `        ``// calculating the ASCII  ` `        ``// value of the string ` `        ``for` `(``int` `i = ``0``; i < len; i++) ` `            ``sum += (``int``)str.charAt(i); ` `         `  `        ``// Find floating point value ` `        ``// of square root of x. ` `        ``long` `squareRoot = (``long``)Math.sqrt(sum); ` `         `  `        ``// If square root is an integer ` `        ``return` `((squareRoot -  ` `                ``Math.floor(squareRoot)) == ``0``); ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main (String[] args) ` `    ``{ ` `        ``String str = ``"d"``; ` `     `  `        ``if` `(isPerfectSquareString(str)) ` `            ``System.out.println(``"Yes"``); ` `        ``else` `            ``System.out.println(``"No"``); ` `    ``} ` `} ` ` `  `// This code is contributed by Ajit. `

## Python3

 `# Python3 program to find  ` `# if string is a perfect  ` `# square or not. ` `import` `math; ` `def` `isPerfectSquareString(``str``): ` `    ``sum` `=` `0``; ` `     `  `    ``# calculating the length ` `    ``# of the string ` `    ``l ``=` `len``(``str``); ` `     `  `    ``# calculating the ASCII  ` `    ``# value of the string ` `    ``for` `i ``in` `range``(l): ` `        ``sum` `=` `sum` `+` `ord``(``str``[i]); ` `     `  `    ``# Find floating point value ` `    ``# of square root of x. ` `    ``squareRoot ``=` `math.sqrt(``sum``); ` `     `  `    ``# If square root is an integer ` `    ``return` `((squareRoot ``-` `             ``math.floor(squareRoot)) ``=``=` `0``); ` ` `  `# Driver code ` `str` `=` `"d"``; ` ` `  `if` `(isPerfectSquareString(``str``)): ` `    ``print``(``"Yes"``); ` `else``: ` `    ``print``(``"No"``); ` ` `  `# This code is contributed by mits `

## C#

 `// C# program to find if string ` `// is a perfect square or not. ` `using` `System; ` ` `  `class` `GFG ` `{ ` `    ``static` `bool` `isPerfectSquareString(``string` `str) ` `    ``{ ` `        ``int` `sum = 0; ` `         `  `        ``// calculating the length ` `        ``// of the string ` `        ``int` `len = str.Length; ` `         `  `        ``// calculating the ASCII  ` `        ``// value of the string ` `        ``for` `(``int` `i = 0; i < len; i++) ` `            ``sum += (``int``)str[i]; ` `         `  `        ``// Find floating point value ` `        ``// of square root of x. ` `        ``double` `squareRoot = Math.Sqrt(sum); ` `        ``double` `F = Math.Floor(squareRoot); ` ` `  `        ``// If square root is an integer ` `        ``return` `((squareRoot - F) == 0); ` `    ``} ` ` `  `    ``// Driver Code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``string` `str = ``"d"``; ` `     `  `        ``if` `(isPerfectSquareString(str)) ` `            ``Console.WriteLine(``"Yes"``); ` `        ``else` `            ``Console.WriteLine(``"No"``); ` `    ``} ` `} ` ` `  `// This code is contributed by Sam007 `

## PHP

 ` `

Output :

```Yes
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : jit_t, Sam007, Mithun Kumar