C++ programing code counts[s[i] - '0'] ++; -


for (int = 0; < s.length(); i++) {    if (isdigit(s[i]))    counts[s[i] - '0'] ++; } 

what code means, 1 can able explain code " counts[s[i] - '0'] ++;" exact opertion

counts ten-element array, being used count how many times each digit appears in s.

specifically:

  • s[i] - '0' turns '0' 0, '1' 1 etc.
  • counts[...]++ increments corresponding element of array.

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -