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