Из заданного текста выберите и напечатайте те символы, которые встречаются в нём ровно один раз — Pascal(Паскаль)/C++(Си)

Pascal

var
  i,j:integer;
  s:string;
begin
read(s);
writeln;
for i:=1 to length(s) do 
 begin
  for j:=0 to i-1 do
   if (s[i]<>s[j]) or (s[i]=' ') then
      for j:=i+1 to length(s) do 
          if (s[i]<>s[j]) or (s[i]=' ') then
               write(s[i],' ');
 end;

end. 

C++

#include <string>
#include <algorithm>
#include <iostream>
#include <locale>
 
int main()
{
   setlocale(LC_ALL, "");
   std::string s = "jhb sdjcnweofnlm wefoi-pokas lknlqkmwdqw";
   std::sort(s.begin(), s.end());
   s.erase(std::unique(s.begin(), s.end()), s.end());
   std::cout << s << std::endl;
 
   return 0;
}

Следующий вариант

#include <stdio.h>
#include <string.h>
 
int main(void) {
    char buf[BUFSIZ], * ptr;
    
    while ( printf("String: ") && fgets(buf, BUFSIZ, stdin) && *buf != '\n' )
        for ( ptr = buf; *ptr; ++ptr )
            if ( strchr(buf, *ptr) == ptr && ! strchr(ptr + 1, *ptr) )
                printf("%c", *ptr);
    
    return 0;
}

Leave a Comment

80 − 71 =