zoukankan      html  css  js  c++  java
  • 在一个字符串(1<=字符串长度<=10000,全部由大小写字母组成)中找到第一个只出现一次的字符,并返回它的位置

    // test20.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    #include<vector>
    #include<string>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string.h>
    #include<deque>
    
    using namespace std;
    
    class Solution {
    public:
    	int FirstNotRepeatingChar(string str) {
    		if (str == "")
    			return -1;
    		int site = 0;
    		int flag = 0;
    		for (int i = 0;i < str.length();i++)
    		{
    			char ch = str[i];
    			for (int j = 0;j < str.length();j++)
    			{
    				if (i != j) //i和j相同的话就是比较的同一个字符
    				{
    					if (ch == str[j]) break;
    					if (j == str.length() - 1) flag = 1; //已经找完所有的数据
    				}
    			
    			}
    			if (flag == 1)
    			{
    				site = i+1;
    				break;
    			}
    		}
    		return site;
    	}
    };
    int main()
    {
    	
    	Solution so;
    	//int count = so.FirstNotRepeatingChar("wangdanwang");
    	int count = so.FirstNotRepeatingChar("");
    	cout << count << endl;
    	
    	
    	
    	cout << endl;
    	return 0;
    }
  • 相关阅读:
    UESTC
    Education Round 8 A
    Gym
    Gym
    hdoj 1159 Common Subsequence
    UVA
    UESTC
    51Nod 1068 Bash游戏 V3 (这规律不好找)
    51Nod 1066 Bash游戏
    51Nod 1002 数塔取数问题
  • 原文地址:https://www.cnblogs.com/wdan2016/p/6021120.html
Copyright © 2011-2022 走看看