标签:blog io os sp for 数据 2014 log ef
题目1283:第一个只出现一次的字符 时间限制:1 秒内存限制:32 兆特殊判题:否提交:1408解决:793 题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现一次的字符。 输入: 输入有多组数据 每一组输入一个字符串。 输出: 输出第一个只出现一次的字符下标,没有只出现一次的字符则输出-1。 样例输入: ABACCDEFF AA 样例输出: 1 -1
#include <iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main(){
string str;
while(cin>>str){
int* ch = new int[256];
for(int i=0;i<256;i++){
ch[i] = 0;
}
for(int i=0;i<str.length();i++){
ch[str[i]]++;
}
int i=0;
for(;i<str.length()&&ch[str[i]]!=1;i++){
}
if(i==str.length()){
printf("-1\n");
}else{
printf("%d\n",i);
}
}
return 0;
}
标签:blog io os sp for 数据 2014 log ef
原文地址:http://blog.csdn.net/hackcoder/article/details/41845647