Unique characters in each string: Difference between revisions

Content added Content deleted
(Added solution for Action!)
(add FreeBASIC)
Line 330: Line 330:
1 2 3 a b c
1 2 3 a b c
</pre>
</pre>

=={{header|FreeBASIC}}==
<lang freebasic>function count_char( s as string, c as string ) as uinteger
'count occurrences of character c in string s
dim as integer i, r = 0
for i = 1 to len(s)
if mid(s,i,1) = c then r += 1
next i
return r
end function

dim as string*20 dat(1 to 3) = {"1a3c52debeffd", "2b6178c97a938stf", "3ycxdb1fgxa2yz"}
dim as string c, uniq
dim as integer i,j

for i = 1 to len(dat(1)) 'go through the first string
c = mid(dat(1),i,1)
for j = 1 to 3
if count_char(dat(j), c)<>1 then goto nexti 'contrary to popular belief, gotos are not evil
next j
for j = 1 to len(uniq)-1 'if it occurs once in every string
if mid(uniq,j+1,1)>c then exit for 'find where we need to put it in alphabetical order
next j
uniq = left(uniq,j)+c+right(uniq,len(uniq)-j) 'and insert it into its correct place
nexti:
next i

print uniq</lang>
{{out}}<pre>123abc</pre>


=={{header|Go}}==
=={{header|Go}}==