-5
total+=!used[str[i]-'a'];
used[str[i]-'a']=1;

It is the condition for checking the characters and saving the value in the variable total.

Dhruv
  • 13
  • 7
  • 1
    What is your question? – Thomas Jager Aug 31 '18 at 12:20
  • i am not getting the function or i can say arithmetic behind these lines like ascii values and all that. – Dhruv Aug 31 '18 at 12:22
  • It's a pangram. – Dhruv Aug 31 '18 at 12:23
  • See: https://stackoverflow.com/help/mcve – Alan Aug 31 '18 at 12:23
  • Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask) as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Then please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve), and [how to debug your programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – Some programmer dude Aug 31 '18 at 12:24
  • You'll learn better if you try to figure this out on your own. Work it out on paper by calculating each part of the expression. – Barmar Aug 31 '18 at 12:25

1 Answers1

2

The total variable will contain the number of unique characters in the array str.

This happens because you increment the count(total+=!used[str[i]-'a']) only if you haven't already marked the character as visited. If you incremented it, you mark it as such in the next line (used[str[i]-'a']=1) so that you wont count it again.

The notation str[i]-'a' is used to shift the ascii values of the characters from 0 to 25 (instead of 97 to 122) so that you can spare some space in the array.

NiVeR
  • 9,644
  • 4
  • 30
  • 35
  • ok but how the value is calculated? – Dhruv Aug 31 '18 at 12:24
  • Why? How? Without explanation this does not really qualify as a useful answer. – Yunnosch Aug 31 '18 at 12:24
  • 1
    Also you make several (quite impressive, my respect) assumptions. They, too, should be explained or at least mentioned. – Yunnosch Aug 31 '18 at 12:25
  • Not an useful answer – Alan Aug 31 '18 at 12:25
  • 'a' what this means and !used[str[i]-'a'] – Dhruv Aug 31 '18 at 12:25
  • @Yunnosch it is a good answer for this kind of question. – TomBombadil Aug 31 '18 at 12:25
  • 1
    +1 for a super concise answer. I think the assumptions @Yunnosch requests are "`used` is initialized as `={0}`", and "the input is text constrained to values from lower-case `a` to lower-case `z`". I think its fine to try to reverse-engineer the constraints of the problem statement from the attempted solution. – lockcmpxchg8b Aug 31 '18 at 12:43
  • @Dhruv Octal numbers, look here: https://stackoverflow.com/questions/17469871/why-010-equals-8. – NiVeR Aug 31 '18 at 14:00
  • ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ – Dhruv Sep 03 '18 at 13:26