Briefest code to find vowels and print consonants

7

Challenge: Read a string from user, print number of each vowel, then place all remaining chars in a line. Shortest answer wins!

Output must look like this:

Enter String: Input

Vowel Count: a: #, e: #, i: #, o: #, u: #

Remaining characters: Vowel-less Input

For example:

Enter String: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!

Caleb Woodman

Posted 2016-05-03T16:10:34.187

Reputation: 223

1Edited to better suit the site. Yeah... Just browsing other questions and even taking the tour isn't much help. Gotta be a better way. – Caleb Woodman – 2016-05-03T16:25:56.577

1

Yeah, that is something that I have been complaining about recently. Your edit makes the post a lot better. The only other thought I have would be to add some test input and output like you had in the first revision. Maybe even some additional test cases.

– James – 2016-05-03T16:27:59.483

5Okay. I can certainly do that. And thank you, wonderful community, for being more forgiving than Stack Overflow to noobs. – Caleb Woodman – 2016-05-03T16:31:42.560

2Is the output format flexible? For example, can the output contain only the numbers (without the vowel names) and then the consonants in a different line? – Luis Mendo – 2016-05-03T16:35:50.897

No not flexible, this interface specifically. – Caleb Woodman – 2016-05-03T16:36:47.280

Also, is the input format flexible? Rather than prompting the user, could I take the string as a function argument? (This is generally the default. You can override the default, but it's not recommended.) – James – 2016-05-03T16:36:57.967

No. It must be an input in this case, I agree, this is a little against the norm :) – Caleb Woodman – 2016-05-03T16:38:06.287

Unfortunately I think this question will boil down to which language has the shortest compression of strings – Blue – 2016-05-03T16:43:57.473

6You're treating lowercase a different than capital A? – AdmBorkBork – 2016-05-03T16:45:02.077

5

Also, for future challenges, I heartily recommend using the Sandbox, so you can elicit feedback before posting to the main page, and thus make your challenge even better. Welcome to PPCG!

– AdmBorkBork – 2016-05-03T16:46:59.123

This is missing a blurb about what characters will be in the input. Will the input include newlines, unicode, etc? From your example it seems like you might not want spaces. – FryAmTheEggman – 2016-05-03T17:13:09.023

4The fun fact is that we are trying to be nice – edc65 – 2016-05-03T19:27:21.150

5

@CalebWoodman I don't think it has anything to do with being a noob or not -- rather, restrictive input/output requirements on non-Kolmogorov challenges shift the focus of the challenge, so that instead of actually doing work on the interesting part, people instead need to account for the I/O requirements, which instead feels like drudgery. Please don't take the downvotes personally (see the PostScript to Peter's answer)!

– AdmBorkBork – 2016-05-03T19:30:00.200

2

Welcome to Programming Puzzles and Code Golf. This might be worth reading. The main problem here is the cumbersome output format, which isn't actually the interesting part of this challenge. Since no one actually gave a solution on how this can be fixed, here's my suggestion. Instead of the long output format, try to change the output format to something like [1, 2, 0, 3, 4] \n LrmIpsmDlrStAmtCnsctrAdpscngElt. Or something else involving just an array and a string :p.

– Adnan – 2016-05-03T20:56:18.377

Do capital vowels not count as vowels (i.e. are not counted and removed)? – Michelfrancis Bustillos – 2016-05-04T12:28:30.350

You're clearly missing a vowel.. (y). You English people and their lack of 'y' as vowels.. shakes head in disappointment – Kevin Cruijssen – 2016-05-04T12:44:15.493

For these purposes, no 'y', but yes, I believe in its vowelitude. – Caleb Woodman – 2016-05-04T15:43:19.473

@KevinCruijssen. And w. Tsk. All the Welsh people must be feeling left out. – TRiG – 2016-05-06T10:41:00.600

Um, crafting my solution-- vowel majuscules seem to be ignored. Is that correct? Otherwise the vowels should be a: 2 e: 5 i: 5 o: 4 and u:3. – Dúthomhas – 2016-05-06T11:53:22.550

Answers

5

05AB1E, 62 bytes

Code:

”‡Á•Ë: ÿ”,”Vowelš‹: ”?"aeiou"©vy": "¹y¢««}", "ý,“«¶šÞ: “ª¹®-J,

Explanation:

There is a lot of string compression going on here. Here is a list of all strings that are compressed:

To see how the actual string compression works, see the Hello, World! answer, or an even more elaborate explanation at the bottom of the Code Review question. Without the string compression, the code looks like this:

"Enter String: ÿ","Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,"Remaining characters: "¹®-J,

Or a more readable 3-part version:

"Enter String: ÿ",
"Vowel Count: "?"aeiou"©vy": "¹y¢««}", "ý,
"Remaining characters: "¹®-J,

Part 1:

We first push the string "Enter String: ÿ". The ÿ here is used for string interpolation. But since the stack is empty, implicit input is requested. The ÿ will be substituted with the user input. We print this with a newline using ,.

Part 2:

We first print the "Vowel Count: " string without a newline using ?. After that, we push the aeiou string, ©opy that to the register and map over the string using v and do the following:

vy": "¹y¢««}    # Mapping loop

v          }    # The loop itself
 y              # Push the current letter (which is a, e, i, o or u)
  ": "          # Push this string
      ¹         # Push the first input again
       y        # Push the letter again
        ¢       # Count the number of occurences of that letter in the input
         ««     # Concatenate to one single string, (e.g. "a: 4")

This leaves 5 different string onto the stack, the stack looks like this now:

stack: ['a: 0', 'e: 1', 'i: 0', 'o: 2', 'u: 0']

We join each element in the stack with ", " using ý. After this, we print it with a newline using ,.

Part 3:

We first push the string "Remaining characters: ". We push the first input again using ¹. We then push "aeiou" which we retrieve from the register using ®. After this, we remove all letters in aeiou using - and Join this with the Remaining characters-string. Finally, we output this with a newline using ,.

Uses CP-1252 encoding. Try it online!.

Adnan

Posted 2016-05-03T16:10:34.187

Reputation: 41 965

2I've seen answers with 05AB1E a couple of times now, but like most languages on this stackexchange I don't understand a lot of it.. Which of the characters in your code-snippet are used for the words "Enter", "String", "Count", "Remaining", and "Characters"? I can clearly see the "Vowelš" in the code (with an š instead of an s..), but I'm clueless about the others. (If possible I'd love a complete description of the entire code-snippet.) – Kevin Cruijssen – 2016-05-04T12:15:18.437

2@KevinCruijssen I have added an explanation. If you have any other questions, feel free to ask them :). – Adnan – 2016-05-04T12:41:25.077

1Wow, thanks for the clear and extended explanation. I know it's not just for me but also in general to others, but I really appreciate the afford explaining it in such a clear way. :) – Kevin Cruijssen – 2016-05-04T12:50:54.823

1This is every sort of amazing! – Caleb Woodman – 2016-05-07T23:52:46.690

3

JavaScript (ES6), 165

Fixed error in output, thx @Neil
3 bytes saved thx @Dom Hastings

a=prompt`Enter String:`.replace(/[aeiou]/g,v=>(V[v]=-~V[v],''),V=[]);alert("Vowel Count: "+[...'aeiou'].map(v=>v+': '+(V[v]|0)).join`, `+`
Remaining characters: `+a)

edc65

Posted 2016-05-03T16:10:34.187

Reputation: 31 086

Needs a space after the comma, but I'm surprised you didn't use a template string with a literal newline character. – Neil – 2016-05-04T00:06:17.197

2@Neil I was careless, with so many unnecessary characters in the output, what's one more... – edc65 – 2016-05-04T06:25:13.497

A couple more bytes you can save, using a template string for the argument to prompt(...) and using |0 instead of ||0. – Dom Hastings – 2016-05-05T08:00:19.907

@DomHastings right, thanks – edc65 – 2016-05-05T08:25:39.850

You need a space after the colon in Enter String: – ericw31415 – 2016-05-05T19:32:57.580

@ericw31415 I don't think so. prompt add a newline anyway – edc65 – 2016-05-05T20:21:40.053

Why do you use prompt instead of a lambda function? – Bálint – 2016-05-06T13:51:38.793

@Bálint Challenge: Read a string from user,... the spec for input / output are strange enough, I take them literally – edc65 – 2016-05-06T13:57:20.013

3

Python, 168 bytes

s=input('Enter String:')
v='aeiou'
print('Vowel Count: '+', '.join([a+':'+str(s.count(a)) for a in v])+'\nRemaining characters: '+''.join([a for a in s if a not in v]))

https://repl.it/CMzO/1

atlasologist

Posted 2016-05-03T16:10:34.187

Reputation: 2 945

1Welcome to PPCG! Nice first post. – Rɪᴋᴇʀ – 2016-05-04T14:03:46.817

3

Java, 272 bytes

class L{public static void main(String[]v){String p=v[0],o="Enter String: "+p+"\nVowel Count:",d=" ",e="aeiou";for(char c:e.toCharArray()){o+=d+c+": "+p.replaceAll("[^"+c+"]","").length();d=", ";}System.out.println("\nRemaining characters: "+p.replaceAll("["+e+"]",""));}}

Ungolfed

class L {
    public static void main(String[] v) {
        String input = v[0], result = "Enter String: " + input + "\nVowel Count:", delimiter = " ", vowels = "aeiou";
        for (char c : vowels.toCharArray()) {
            result += delimiter + c + ": " + input.replaceAll("[^" + c + "]", "").length();
            delimiter = ", ";
        }
        System.out.println("\nRemaining characters: " + input.replaceAll("[" + vowels + "]", ""));
    }
}

Notes

  • Input via program arguments: Save as L.java, compile with javac L.java, run with java L LoremIpsumDolorSitAmetConsecuteurAdipscingElit!

Output

Enter String: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!

Marv

Posted 2016-05-03T16:10:34.187

Reputation: 839

I know it's a while, but you can golf it to 246 bytes like this: interface M{static void main(String[]v){String p=v[0],o="Enter String: "+p+"\nVowel Count:",d=" ",e="aeiou";for(String c:e.split("")){o+=d+c+": "+~-p.split(c,-1).length;d=", ";p=p.replace(c,"");}System.out.print(o+"\nRemaining characters: "+p);}} Try it here.

– Kevin Cruijssen – 2017-11-13T08:31:06.853

2

Perl 5, 127 bytes

$_=<>;print"Enter String: ${_}Vowel Count:";for$s(a,e,i,o,u){print" $s: ".~~s/$s//g,$s!~u&&","}print"
Remaining characters: $_"

Many thanks to Dom Hastings (in a comment hereon) for 14 bytes.

msh210

Posted 2016-05-03T16:10:34.187

Reputation: 3 094

I had a slightly different approach using a loop, can you use the same mechanism to save bytes? sub p{print@_}p"Enter String: ";$_=<>;p"Vowel Count:";for$s(a,e,i,o,u){p" $s: ".~~s/$s//g,$s!~/u/&&","}p"\nRemaining characters: $_" (note: \n is a literal newline!) – Dom Hastings – 2016-05-04T09:23:31.507

@DomHastings, many thanks, that saves a bunch. – msh210 – 2016-05-04T15:20:38.503

2

PostgreSQL, 295, 263 bytes

SELECT v "Enter string:", string_agg(r,', 'ORDER BY n) "Vowel Count:",TRANSLATE(v,'aeyiou','') "Remaining characters:"
FROM (SELECT 'LoremIpsumDolorSitAmetConsecuteurAdipscingElit!'::text v)s
,LATERAL(SELECT LENGTH(v)l)a
,LATERAL(SELECT c||': '||l-LENGTH(REPLACE(v,c,''))r,n FROM (VALUES('a',1),('e',2),('i',3),('o',4),('u',5))t(c,n))b
GROUP BY v

SqlFiddleDemo

Output:

╔══════════════════════════════════════════════════╦═══════════════════════════════╦══════════════════════════════════╗
║                  Enter string:                   ║         Vowel Count:          ║      Remaining characters:       ║
╠══════════════════════════════════════════════════╬═══════════════════════════════╬══════════════════════════════════╣
║ LoremIpsumDolorSitAmetConsecuteurAdipscingElit!  ║ a: 0, e: 4, i: 4, o: 4, u: 3  ║ LrmIpsmDlrStAmtCnsctrAdpscngElt! ║
╚══════════════════════════════════════════════════╩═══════════════════════════════╩══════════════════════════════════╝    

Input: (SELECT '...'::text v)s

How it works:

  • (SELECT 'LoremIpsumDolorSitAmetConsecuteurAdipscingElit!'::text v)s input
  • ,LATERAL(SELECT LENGTH(v)l)a - length of input
  • (VALUES('a',1),('e',2),('i',3),('o',4),('u',5)) - vowels with oridinal
  • SELECT c||': '||l-LENGTH(REPLACE(v,c,''))r,n - calculate number of occurences
  • string_agg(r,', 'ORDER BY n) ... GROUP BY v combine result
  • TRANSLATE(v,'aeyiou','') string without vowels

EDIT 3:

Removed additional LATERAL, input moved to table.

SELECT v"Enter string:",string_agg(r,', 'ORDER BY n)"Vowel Count:",TRANSLATE(v,'aeyiou','')"Remaining characters:"
FROM s,LATERAL(SELECT c||': '||LENGTH(v)-LENGTH(REPLACE(v,c,''))r,n FROM(VALUES('a',1),('e',2),('i',3),('o',4),('u',5))t(c,n))b
GROUP BY v

SqlFiddleDemo

lad2025

Posted 2016-05-03T16:10:34.187

Reputation: 379

I'm still amazed how people use SQL for anything other than databases – Bálint – 2016-05-06T13:50:14.683

@Bálint In all my answers I use SQL . In production I would not use this kind of code but as puzzle why not. – lad2025 – 2016-05-06T21:31:04.350

This would appear to hardcode the input and does not show the prompt required in the question. – cat – 2016-05-08T00:31:07.890

Output must look like this – cat – 2016-05-08T00:32:08.047

@cat Added version with table. Output must look like this with SQL (declarative statement) you cannot get interactive prompt. – lad2025 – 2016-05-08T05:31:26.350

2

Lua, 242 Bytes

For a moment, I thought that it will be longer than SQL... still a monster for such a simple task.

t={}x="aeiou"i=io.write 
x:gsub(".",function(c)t[c]=0 end)i("Enter string: ")z=io.read()s="Remaining characters: "..z:gsub(".",function(c)if x:find(c)then
t[c]=t[c]+1return""end end)i("Vowel Count: ")x:gsub(".",function(c)i(c..": "..t[c]..(c=="u"and"\n"or", "))end)i(s)

The job is done by the part

z:gsub(".",function(c)if x:find(c)then t[c]=t[c]+1return""end end)

Everything else is mainly for the purpose of outputing in the right format.

Ungolfed

t={}                             -- create an empty array
x="aeiou"                        -- list of vowels
i=io.write                       -- shorthand for outputing
x:gsub(".",function(c)t[c]=0 end)-- create a celle at 0 for each vowel
i("Enter string: ")              -- output some boilerplate
z=io.read()                      -- take the input
s="Remaining characters: "..     -- save in s the concatenation of this string
  z:gsub(".",function(c)         -- and the result of gsubing on each character of the input 
  if x:find(c)                   -- if the current char is a vowel
  then
    t[c]=t[c]+1                  -- increment its counter
    return""                     -- suppress it from the input
  end
end)

i("Vowel Count: ")               -- output some more boilerplate
x:gsub(".",function(c)           -- iterate over the vowels
  i(c..": "..t[c]..              -- output "l: #" appended with
    (c=="u"
        and"\n"                  -- "\n" if the current char is "u"
      or", "))                   -- ", " otherwise
end)
i(s)                             -- output the content of s

Katenkyo

Posted 2016-05-03T16:10:34.187

Reputation: 2 857

2

Python, 220 201 bytes

This is my first submission on codegolf so go easy. :P

def f(y):
  global x;c=x.count(y);x=x.replace(y,'');return c;
x=input('Enter string: ');print('Vowel Count: a: {}, e: {}, i: {}, o: {}, u: {}'.format(*map(f,"aeiou")));print('Remaining characters: '+x)

Ungolfed:

def f(y):
  global x
  c=x.count(y)
  x=x.replace(y,'')
  return c;
x=input('Enter string: ')
print('Vowel Count: a: {}, e: {}, i: {}, o: {}, u: {}'.format(*map(f,"aeiou")))
print('Remaining characters: '+x)

Output:

Enter string: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!

abybaddi009

Posted 2016-05-03T16:10:34.187

Reputation: 151

1Welcome to Code Golf! You might be able to save some bytes by using Python's list comprehensions and unpacking them into the format function instead of calling each function individually: ...u: {}'.format(*[f(c)for c in 'aeiou']). Also, I think you can put the commands from a function on the same line right after the colon and it should work, saving some bytes. – Value Ink – 2016-05-07T06:51:45.197

2@KevinLau-notKenny It might be shorter to do .format(*map(f,"aeiou")) – cat – 2016-05-08T00:35:08.580

2

JavaScript, 190 186 bytes

(s,a=[..."aeiou"].map(v=>(s.match(v,"g")||[]).length))=>`Enter String: ${s}
Vowel Count: ${[..."aeiou"].map((v,i)=>v+": "+a[i]).join`, `}
Remaining characters: `+s.replace(/[aeiou]/g,"")

I just remembered that literal newlines are only 1 byte! Also remembered to golf something I missed before.

ericw31415

Posted 2016-05-03T16:10:34.187

Reputation: 2 229

Why do you use RegExp(expression, modifier) instead of /expression/modifier? – Bálint – 2016-05-06T10:36:40.740

I need to plug in the v into the RegExp. If I used /v/g, the v would be a literal string instead of the value of the variable. – ericw31415 – 2016-05-06T11:55:41.850

1

PowerShell v2+, 196 149 bytes

$z=read-host "Enter string"
"Vowel Count: "+(([char[]]"aeiou"|%{$_+": "+($z.length-($z=$z-creplace$_).length)})-join', ')
"Remaining characters: "+$z

Takes input via read-host with a prompt, save into $z.

We then output a string literal "Vowel Count: " concatenated with the result of a loop/join through the vowels to construct the a: #, e: #,... string. This is done by taking the current string's .length minus the new string's .length after we perform a case-sensitive replacement with -creplace (i.e., how many did we remove). In addition, we re-save the result of the replace back into $z for the next loop.

We then also output the second string literal concatenated with whatever is still left in $z.

This keeps the current specification intact, in that capital vowels are distinguished from lowercase vowels, since -creplace is explicitly case sensitive.

Examples

PS C:\Tools\Scripts\golfing> .\briefest-code-find-vowels.ps1
Enter string: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!

PS C:\Tools\Scripts\golfing> .\briefest-code-find-vowels.ps1
Enter string: ProgrammingPuzzlesAndCodeGolf
Vowel Count: a: 1, e: 2, i: 1, o: 3, u: 1
Remaining characters: PrgrmmngPzzlsAndCdGlf

AdmBorkBork

Posted 2016-05-03T16:10:34.187

Reputation: 41 581

1

Retina, 133 bytes

(a()|e()|i()|o()|u()|.)+
Enter string: $&¶Vowel count: a: $#2, e: $#3, i:$#4, o:$#5, u:$#6¶Remaining characters: $&
(?<=s:.+)[aeiou]
<empty-line>

Try it online!

Who is more fit for this challenge than Retina?

Leaky Nun

Posted 2016-05-03T16:10:34.187

Reputation: 45 011

1

Groovy, 181 177 bytes

online

​{i->r=[:].withDefault{0};o=i.toLowerCase().replaceAll(/[aeiou]/,{r[it]++;''})
"Enter String: $i\nVowel Count: ${r.collect{k,v->"$k: $v"}.join(' ')}\nRemaining characters: $o"}

Krzysztof Atłasik

Posted 2016-05-03T16:10:34.187

Reputation: 189

1

Tcl, 184 (counting majuscule vowels) / 180 (ignoring them)

puts -nonewline {Enter String: }
flush stdout
gets stdin s
set c {Vowel Count:}
foreach v {a e i o u} {append c " $v: [regsub -all (?i)$v $s {} s]"}
puts "$c\nRemaining Characters: $s"

Explanation

Most of the code is actually dealing with the strict I/O requirements. The remainder works by doing a regular expression substitution (deletion) on the input string $s for every vowel and appending the vowel $v and associated number of substitutions to the output string $c.

The above code works for mixed-case vowels. Remove the (?i) option from the regular expression on the penultimate line for strictly minuscule vowels.

Dúthomhas

Posted 2016-05-03T16:10:34.187

Reputation: 541

1

C# 317 bytes

string t=Console.ReadLine();Dictionary v = new Dictionary<char,int>{{'a',0},{'e',0},{'i',0},{'o',0},{'u',0}};string o="";foreach(char c in t){if(v.Keys.Contains(c)){v[c]++;}else{o+=c;}}Console.WriteLine("a: "+v['a']+", e: "+v['e']+", i: "+v['i']+", o: "+v['o']+", u: "+v['u']);Console.WriteLine("Remaining Characters: "+o);

Any suggestions, trying to learn to golf with C#. 1KB is obviously way bigger than the other answers though.

Ungolfed:

string t=Console.ReadLine();
Dictionary v = new Dictionary<char,int>
{
    {'a',0},
    {'e',0},
    {'i',0},
    {'o',0},
    {'u',0}
};
string o="";
foreach(char c in t)
{
    if(v.Keys.Contains(c))
    {
        v[c]++;
    }
    else
    {
        o+=c;
    }
}
Console.WriteLine("a: "+v['a']+", e: "+v['e']+", i: "+v['i']+", o: "+v['o']+", u: "+v['u']);
Console.WriteLine("Remaining Characters: "+o);

Robbie Coyne

Posted 2016-05-03T16:10:34.187

Reputation: 123

Please specifiy an exact byte count in the future, 1 KB is way off from 317 bytes, wich isn't that bad. – Bálint – 2016-05-06T13:54:16.933

@Bálint Using school computer, it's cryptic getting to the properties of a file for some reason. – Robbie Coyne – 2016-05-06T13:59:31.780

I'd suggest using a regex ( /[aeiou]/ instead of a dictionary, an use that to match strings – Bálint – 2016-05-06T14:00:40.683

Just use an online byte counter. – Bálint – 2016-05-06T14:01:37.073

like http://mothereff.in/byte-counter

– cat – 2016-05-08T00:37:52.693

1

Python 162 Bytes

v,s="aeiou",input()
print "String:"+s+"\n"+"Vowel Count"+" ".join([c+":"+str(s.count(c)) for c in v])+"\n"+"Remaining Characters:"+filter(lambda x:v.count(x)<1,s)

JoshK

Posted 2016-05-03T16:10:34.187

Reputation: 139

0

Ruby, 202 bytes

print"Enter String: ";t=gets;c=->(x){t.chars.count(x)};a="aeiou".chars
s=a.zip(a.map(&c)).map{|e|"#{e[0]}: #{e[1]}"}.join(", ");r=t.gsub(/[aeiou]/,"")
puts"Vowel Count: #{s}\nRemaining characters: #{r}"

jose_castro_arnaud

Posted 2016-05-03T16:10:34.187

Reputation: 229

Use $><< instead of print. Do s="aeiou".chars.map{|e|"#{e}: #{t.count e}"}*", " to save a ton of bytes over setting up lambdas and zipping things together. Use t.tr('aeiou','') instead of gsub to replace, and maybe put it directly into where you have #{r} instead of assigning it. – Value Ink – 2016-05-04T00:01:05.820

0

C++, 449 bytes

Golfed:

#include <iostream>
#include <string>
int main(){std::string x;std::cout<<"Enter String: ",std::cin>>x;int a=0,e=0,i=0,o=0,u=0;for(int c=0;c<x.length();c++){switch(x[c]){case 'a':a++;x.erase(c,1);break;case 'e':e++;x.erase(c,1);break;case 'i':i++;x.erase(c,1);break;case 'o':o++;x.erase(c,1);break;case 'u':u++;x.erase(c,1);break;}}std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;}

Ungolfed:

#include <iostream>
#include <string>

int main(){
    std::string x;
    std::cout<<"Enter String: ", std::cin>>x;
    int a=0,e=0,i=0,o=0,u=0;
    for(int c = 0; c < x.length(); c++){
        switch(x[c]){
            case 'a':
                a++;
                x.erase(c,1);
                break;
            case 'e':
                e++;
                x.erase(c,1);
                break;
            case 'i':
                i++;
                x.erase(c,1);
                break;
            case 'o':
                o++;
                x.erase(c,1);
                break;
            case 'u':
                u++;
                x.erase(c,1);
                break;
        }
    }
    std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;
}

Michelfrancis Bustillos

Posted 2016-05-03T16:10:34.187

Reputation: 695

does case 'u', et al really need a space? I don't have a C compiler in front of me right now but I don't think it does. – cat – 2016-05-08T00:33:13.767

0

C++17, 313 bytes

#include <cctype>
#include <iostream>
#include <string>
using namespace std;int main(){int n,h[6]={0};string s,v="aeiou",r;cout<<"Enter String: ";getline(cin,s);for(c:s){h[n=v.find(tolower(c))+1]++;if(!n)r+=c;}cout<<"Vowel Count:";n=1;for(c:v)cout<<" "<<c<<": "<<h[n++];cout<<"\nRemaining Characters: "<<r<<"\n";}

I suppose I could make this just a function to eliminate standard boilerplate from the byte count.

Ungolfed

#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main()
{
  int n;
  int histogram[6] = {0};   // { (consonants), A, E, I, O, U }
  string source;
  string vowels = "aeiou";  // vowel order matches the histogram
  string consonants;

  cout << "Enter String: ";
  getline( cin, source );

  for (c : source)
  {
    // n ← consonants=0, A=1, E=2, ...
    n = vowels.find( tolower(c) ) + 1;
    histogram[n]++;
    if (!n)
      consonants += c;
  }

  cout<<"Vowel Count:";
  n = 1;
  for (vowel : vowels)
    cout << " " << vowel << ": " << histogram[n++];

  cout << "\nRemaining Characters: " << consonants << "\n";
}

Explanation

Computes a histogram using the std::string lookup functions.

Again, you can eliminate 27 bytes from the count if only minuscule vowels matter. (Remove the first #include and the call to tolower().)

Dúthomhas

Posted 2016-05-03T16:10:34.187

Reputation: 541

0

Ruby, 134 133 131 bytes

Because the other Ruby answer didn't respond to my suggestions, I golfed it down further myself.

-2 bytes from @manatwork

$><<"Enter String: "
r=gets.tr v='aeiou',''
puts"Vowel Count: #{v.chars.map{|e|e+": #{$_.count e}"}*', '}
Remaining characters: "+r

Value Ink

Posted 2016-05-03T16:10:34.187

Reputation: 10 608

1r=gets.tr v='aeiou','' – manatwork – 2016-05-09T14:18:16.370