找出字符串中第一个只出现一次的字符
2015-08-10 20:55
330 查看
#include<iostream> #include<string> using namespace std; int main(){ string input; string str; getline(cin, input); int flag = 1; if(input.length() == 1){ cout<<input<<endl; return 0; } int position = 0; for(int i = 0; i < input.length(); i++){ str.assign(1, input[i]); // cout<<"str = "<<str<<endl; position = input.find(str, 0); if(position == input.length() - 1) {cout<<str<<endl; return 0;} else if(input.find(str, position + 1) == input.npos) {cout<<str<<endl; return 0;} } cout<<"."<<endl; return 0; }
相关文章推荐
- java泛型(二)、泛型的内部原理:类型擦除以及类型擦除带来的问题
- Android之——NDK环境搭建
- iOS9 Beta5内置壁纸—艺术家的文艺范
- CSU 1115 最短的名字
- HDOJ 1503 Advanced Fruits(LCS)
- UVALive 6935 Bricks题解
- VS2015“检测到在集成的托管管道模式下不适用的 ASP.NET 设置”的最终解决办法
- CLRS第三章思考题
- C++使用简单的函数指针
- Generate Parentheses
- Oil Deposits
- mac os OS X 优山美地(Yosemite)如何提高最大连接数限制
- 03 推箱子
- 并发编程之一:多进程
- LeetCode(26) Remove Duplicates from Sorted Array
- CSU 1113 Updating a Dictionary
- WPF 实现带标题的TextBox
- poj 2367 Genealogical tree (拓扑排序)
- LeetCode(26) Remove Duplicates from Sorted Array
- 【Java】【Flume】Flume-NG阅读源代码AvroSink