出一个字符中只出现过一次且是出现一次的字符串中最先出现的字符
2015-08-16 22:51
323 查看
找出一个字符中只出现过一次且是出现一次的字符串中最先出现的字符: 下面的代码在vc6.0上面编译要出问题,只能说,vc6.0 不适合写c++的代码,除了内存占用小点,没什么好处 #include <iostream> #include <string> using namespace std; int main() { int n ; string str; cin>>n; //getchar(); while(n > 0) { n -- ; getline(cin,str,'\n'); // getchar(); int len = str.size(); cout<<len<<endl; int strarr[256] = {0}; int pos = -1; for(int i = 0 ; i < len ; i ++) { strarr[str[i]] ++; } for(int j = 0 ; j < len ; j ++) { if(strarr[str[j]] == 1) { pos = j ; break; } } if(pos != -1) cout<<str[pos]; } return 0; }
相关文章推荐
- Lua中的面向对象
- POJ 3468 A Simple Problem with Integers // 线段树 区间更新
- 命令行编译、运行java
- Visual Studio 2015的“转到定义”和“查看定义”出错的Bug
- httplib,urllib和urllib2
- 瀑布流在Angularjs中的使用
- & 和 && 的区别
- 两台linux系统免密码登陆
- [JAVA]定时任务之-Quartz使用篇
- 使用 create 命令建立数据库v, 并利用sp_helpdb查看数据库文件
- Unsupported major.minor version 51.0解决办法
- POJ 2528 Mayor's posters (线段树+离散化 成段替换)
- HDU - 1757 A Simple Math Problem(矩阵快速幂)
- Dialog对话框的四种显示样式
- C#的try…catch语句
- 设计模式(二十一)之 Visitor
- 转:JVM的相关知识整理和学习
- Linux内核管理风范
- 编译器根据属性自动添加实例变量
- java入门