r/badcode • u/LVNmaster • Oct 17 '21
c++ Checking if a string has at least one each character in the alphabet. This is actually real.
646
Upvotes
r/badcode • u/LVNmaster • Oct 17 '21
40
u/xigoi Oct 17 '21
Doesn't this check if there's an odd number of distinct letters?
238
u/glitched-dream Oct 17 '21
This reminds me of the days programmers were paid by line. Gonna code me up a Cadillac.
63
u/bugqualia Oct 17 '21
Suggest your right way, but only think for 10 seconds:
Gogogo
71
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 17 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
10
u/Magnus_Tesshu Oct 17 '21 edited Oct 17 '21
are you programming spambots or those weird suggestive ads or something?
That aside,
int i = something; char a[10001]; ... later ... i[a]wtfAnyway best style guide is to put newlines on separate lines but then also compress two statements on the same line as an if statement for space efficiency. I like that they have
breaks in there for runtime efficiency though.6
u/EkskiuTwentyTwo i -= (i - (-1)) - i Oct 18 '21
At least it's O(n)
8
u/zed_three Oct 17 '21
This doesn't even work!
alphaisn't initialised properly, but is presumably assumed to be full of zeroes? It could be filled with anything.And then it actually checks of there are an odd number of different letters, rather than at least one of each.
The use of
i[a]in the first loop in main is pretty suspicious -- knowing about that and why it works is not something a beginner would know, but the rest of the code looks like something a beginner would write4
u/Spynder shameless stealing content to r/YandereTechnique Oct 17 '21
This is loop-variant of r/YandereTechnique
1
u/SexyMuon Oct 17 '21
This can't be real. Nice try tho!
1
u/wktr_t Oct 17 '21
I want this font.
1
u/chestera321 Oct 18 '21
Is this from CodeForces?
2
u/Drakethos Oct 18 '21
Um char dude for int I < string.Len If (word[i] > a or Z ) Do shit
Done going on break. Collect massive paycheck
1
u/XDracam Oct 17 '21
Technically it doesn't matter much whether you have n loops with 1 check or 1 loop with n checks, even though the single loop reads nicer. In this case however, you only need a >= and a <= check. Or a library function...
1
u/[deleted] Oct 18 '21
Aargh! My eyes! Oh, the horror.
1
u/trutheality Oct 18 '21
When you know what a for loop does but not when to use one.
-1
u/thanatica Oct 17 '21
Good luck rolling this out in China...
0
u/[deleted] Oct 17 '21
[deleted] — view deleted comment
8
u/[deleted] Oct 17 '21
[removed] — view removed comment