Programming Basics String--02 Find the first occurrence of a character

Source: Internet
Author: User

Describe

Given a string that contains only lowercase letters, you find the first character that appears only once. If not, output No.

Enter a string that is less than 100000 in length. Outputs the first character that appears only once, and outputs no if none. Sample input

Abcabd

Sample output

C
Couldn't do it, but got two others ' answers;
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Chara[100100];6 intMain () {7     inti,j,k=0, l=0;8 gets (a);9L=strlen (a);Ten      for(i=0; i<l;i++) One     { A          for(j=0; j<l;j++) -         if(a[i]==a[j]&&i!=j) -k=1; the         if(k==0) {cout<<a[i];return 0; -         } -k=0; -     } +cout<<"No";  -}

Above this more understand!

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intMain ()6 {7 Chars[110000],b;8 inta[ -]={0},k,q=0;9 gets (s);Ten intw=strlen (s); One  for(intI=0; i<=w-1;++i) A{k=s[i]- the; -a[k]+=1;} -  for(intI=0; i<=w-1;++i) the{k=s[i]- the;  - if(a[k]==1)  -{b= the+k;q=1;cout<<b; Break;}} - if(q==0) cout<<"No"; + return 0; -}

I can't read this! The last is my own, and now do not know what is wrong!

1#include <stdio.h>2#include <string.h>3 intT,i,j,flag,len;4 Chara[200000]; 5 intMain ()6 { 7 8 gets (a);9len=strlen (a);Ten          for(i=0; i<len-1; i++)  One         {  Aflag=1;  -             if(a[i]=='@')Continue;//for the same, omitted; -              for(j=i+1; j<len;j++)//j=j+1 can not use the letter before the loop i.  the                 if(a[i]==A[j]) -                 {  -a[j]='@';//mark the same letter.  -flag=0;//not output A[I]; +                 }  -             if(flag==1)  +             {  A Putchar (A[i]); at                  Break;  -             }  -         }  -     if(i==len-1) printf ("No");  -     return 0;  -}

Programming Basics String--02 Find the first occurrence of a character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.