python找出只出现一次的字符_找出字符串中第一个只出现一次的字符(题面已经更新)...

0

#include

#include

#include

int main(){

using namespace std;

string inp;

int nu;

char oup;

while(cin>>inp){

int len=inp.size();

vectornum(26,0);

for(int i=0;i

num[inp[i]-'a']++;

}

for(int j=0;j

if(num[inp[j]-'a']==1)

{nu=1;

oup=inp[j];

break;}

else nu=-1;

}

if(nu==1)cout<

else cout<

}

return 0;

}

发表于 2016-09-20 22:58:18

回复(0)

更多回答

32

#include

#include

int main()

{

using namespace std;

string str;

while(getline(cin,str))

{

unsigned int i;

for (i=0;i

{

if(str.find(str[i])==str.rfind(str[i]))

{

cout<

break;

}

}

if(i==str.size())

cout<

}

return 0;

}

发表于 2016-06-17 10:00:29

回复(12)

21

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(sc.hasNext()){

String str = sc.nextLine();

char[] cs = str.toCharArray();

for(int i = 0; i < cs.length; i++){

if(str.indexOf(cs[i]) == str.lastIndexOf(cs[i])){

System.out.println(cs[i]);

break;

}

}

}

sc.close();

}

}

发表于 2016-08-14 21:35:45

回复(8)

7

/*思路:每出现一次,就在对应数组中计数+1*/

#include

#include

using namespace std;

int main()

{

string str;

while(getline(cin,str))

{

int a[128]={0};//保存出现次数

bool flag=false;//判断是否找到

for(int i=0;i

++a[str[i]];

for(int i=0;i

if(a[str[i]]==1)//判断是否是第一个只出现一次的字符

{

cout<

flag=true;

break;//注意要break;

}

if(flag==false)//如果没有找到

cout<

}

return 0;

}

编辑于 2016-12-19 16:52:29

回复(3)

5

while True:

try:

string = input()

for i in string:

if string.count(i) == 1:

print(i)

break

else:

print(-1)

except:break

发表于 2020-03-27 23:54:10

回复(5)

5

用哈希统计词频

#include

#include

using namespace std;

const int tableS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值