标签:main == name style code blog div turn for
给定一个只包含小写字母的字符串,请你找到第一个仅出现一次的字符。如果没有,输出no。
abcabd
c
错误答案:9分
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<math.h> using namespace std; char a[30][2]; string w; int main() { int i,n,k; char j=‘a‘; for(i=1;i<=26;i++) { a[i][1]=j; j++; } cin>>w; n=w.length(); for(i=0;i<n;i++) { for(k=1;k<=26;k++) { if(a[k][1]==w[i]) {a[k][2]++;continue; } } } int f=0; for(i=1;i<=26;i++) { if(a[i][2]==1){f=1;cout<<a[i][1]<<endl;break;} } if(f==0) cout<<"no"<<endl; return 0; }
正确答案:
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main() { char a[100001]; int b,c[100001]={0}; gets(a); b=strlen(a); for(int i=0;i<b;i++) { for(int j=0;j<b;j++) { if(a[i]!=a[j])c[i]++; } if(c[i]==b-1) { cout<<a[i];return 0; } } cout<<"no"; return 0; }
标签:main == name style code blog div turn for
原文地址:http://www.cnblogs.com/voldemorte/p/7157058.html