Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11

C (gcc), (削除) 97 (削除ここまで) 94(削除) 94 (削除ここまで) 87 bytes

  • -3 thanks to Unrelated String
  • -7 thanks to c--

Uses uppercase as the challenge only states case-insensitive.

f(char*s){for(int a[96]={},i=64;for(;*s;i=64;i<90;)a[*s++&95]++;for(;++i<91;a[i]&&printf*s?a[*s++&95]++:a[++i]&&printf("%c:%d ",i,a[i]));}

Try it online! Try it online!

Ungolfed:

f(char*s){
 for(int a[96]={},i=64;
 for(;*s; i<90;)a[*s++&95]++; // uppercasefor lettersall (don'tcharacters carein aboutstring, others)then andfrom increment'A' countto 'Z':
 for(;++i<91; *s? // fromdone 'A'processing tostring?
 'Z' a[*s++&95]++: // no, uppercase letter and increment count
 a[i]&&printfa[++i]&&printf("%c:%d ",i,a[i])); // print count if greateryes, thanprint zerocounts
}

C (gcc), (削除) 97 (削除ここまで) 94 bytes

  • -3 thanks to Unrelated String

Uses uppercase as the challenge only states case-insensitive.

f(char*s){int a[96]={},i=64;for(;*s;)a[*s++&95]++;for(;++i<91;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online!

Ungolfed:

f(char*s){
 int a[96]={},i=64;
 for(;*s;)a[*s++&95]++; // uppercase letters (don't care about others) and increment count
 for(;++i<91; // from 'A' to 'Z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}

C (gcc), (削除) 97 (削除ここまで) (削除) 94 (削除ここまで) 87 bytes

  • -3 thanks to Unrelated String
  • -7 thanks to c--

Uses uppercase as the challenge only states case-insensitive.

f(char*s){for(int a[96]={},i=64;i<90;)*s?a[*s++&95]++:a[++i]&&printf("%c:%d ",i,a[i]);}

Try it online!

Ungolfed:

f(char*s){
 for(int a[96]={},i=64;
  i<90;) // for all characters in string, then from 'A' to 'Z':
 *s? // done processing string?
  a[*s++&95]++: // no, uppercase letter and increment count
 a[++i]&&printf("%c:%d ",i,a[i]); // yes, print counts
}
Code shortening
Source Link
ErikF
  • 4.8k
  • 9
  • 11

C (gcc), 97(削除) 97 (削除ここまで) 94 bytes

  • -3 thanks to Unrelated String

Uses uppercase as the challenge only states case-insensitive.

f(char*s){int a[256]=a[96]={},i;fori=64;for(;*s;)a[*s++|32]++;fora[*s++&95]++;for(i=96;++i<123;a[i]&&printf;++i<91;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online! Try it online!

Ungolfed:

f(char*s){
 int a[256]=a[96]={},i;i=64;
 for(;*s;)a[*s++|32]++;a[*s++&95]++; // lowercaseuppercase letters (don't care about others) and increment count
 for(i=96;++i<123;;++i<91; // from 'a''A' to 'z''Z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}

C (gcc), 97 bytes

f(char*s){int a[256]={},i;for(;*s;)a[*s++|32]++;for(i=96;++i<123;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online!

Ungolfed:

f(char*s){
 int a[256]={},i;
 for(;*s;)a[*s++|32]++; // lowercase letters (don't care about others) and increment count
 for(i=96;++i<123; // from 'a' to 'z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}

C (gcc), (削除) 97 (削除ここまで) 94 bytes

  • -3 thanks to Unrelated String

Uses uppercase as the challenge only states case-insensitive.

f(char*s){int a[96]={},i=64;for(;*s;)a[*s++&95]++;for(;++i<91;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online!

Ungolfed:

f(char*s){
 int a[96]={},i=64;
 for(;*s;)a[*s++&95]++; // uppercase letters (don't care about others) and increment count
 for(;++i<91; // from 'A' to 'Z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}
Adjusted upper array bound
Source Link
ErikF
  • 4.8k
  • 9
  • 11

C (gcc), 97 bytes

f(char*s){int a[255]=a[256]={},i;for(;*s;)a[*s++|32]++;for(i=96;++i<123;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online! Try it online!

Ungolfed:

f(char*s){
 int a[255]=a[256]={},i;
 for(;*s;)a[*s++|32]++; // lowercase letters (don't care about others) and increment count
 for(i=96;++i<123; // from 'a' to 'z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}

C (gcc), 97 bytes

f(char*s){int a[255]={},i;for(;*s;)a[*s++|32]++;for(i=96;++i<123;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online!

Ungolfed:

f(char*s){
 int a[255]={},i;
 for(;*s;)a[*s++|32]++; // lowercase letters (don't care about others) and increment count
 for(i=96;++i<123; // from 'a' to 'z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}

C (gcc), 97 bytes

f(char*s){int a[256]={},i;for(;*s;)a[*s++|32]++;for(i=96;++i<123;a[i]&&printf("%c:%d ",i,a[i]));}

Try it online!

Ungolfed:

f(char*s){
 int a[256]={},i;
 for(;*s;)a[*s++|32]++; // lowercase letters (don't care about others) and increment count
 for(i=96;++i<123; // from 'a' to 'z':
 a[i]&&printf("%c:%d ",i,a[i])); // print count if greater than zero
}
Source Link
ErikF
  • 4.8k
  • 9
  • 11
Loading

AltStyle によって変換されたページ (->オリジナル) /