摘要: 刚开始还在想双指针,完全没必要。然后最土的可以扫两遍O(n),用一个数组记录出现次数。然后想到如果数组里记录出现的位置,可以只扫一遍O(n),第二遍扫字符集就行了。#include #include using namespace std; #define INF 1> s) { int len = s.length(); if (len == 0) { cout count[i] && count[i] != -1) min = count[i]; } if (min != INF) cout... 阅读全文
posted @ 2013-11-02 23:31 阿牧遥 阅读(155) 评论(0) 推荐(0)
摘要: 老题,两个stack。其中一个维护min值就行了。#include #include using namespace std; int main(){ int n; while (cin >> n) { stack st; stack min; while (n--) { char ch; cin >> ch; if (ch == 's') { int k; cin >> k... 阅读全文
posted @ 2013-11-02 22:54 阿牧遥 阅读(203) 评论(0) 推荐(0)
摘要: 这道题见过,就是把相加的结果作为比较来排序就行了。注意的是comp函数里面要用const引用。而且c++里的字符串直接操作(读入和相加)也很方便。#include #include #include #include #define LEN 105using namespace std; string s[LEN]; bool comp(const string &a, const string &b){ string s1 = a + b; string s2 = b + a; return s1 > m) { for (int i = 0; i > s... 阅读全文
posted @ 2013-11-02 22:22 阿牧遥 阅读(215) 评论(0) 推荐(0)
摘要: 用一个栈辅助,模拟过程+判断就可以了。#include #include #include #define LEN 100005using namespace std;int A[LEN];int B[LEN];int main(){ int n; while (cin >> n) { for (int i = 0; i > A[i]; } for (int i = 0; i > B[i]; } stack st; int i = 0; int j = 0; whi... 阅读全文
posted @ 2013-11-02 22:15 阿牧遥 阅读(225) 评论(0) 推荐(0)
摘要: 找到以后要再扫一遍确认。http://zhedahht.blog.163.com/blog/static/25411174201085114733349/#include #include #define LEN 100005#define ulong unsigned long longusing namespace std;ulong A[LEN];int main(){ int n; while (cin >> n) { for (int i = 0; i > A[i]; } int count = 0; ulon... 阅读全文
posted @ 2013-11-02 20:26 阿牧遥 阅读(231) 评论(0) 推荐(0)
摘要: 使用异或和与,模拟机器的加法。http://blog.csdn.net/htyurencaotang/article/details/11125415#include #include using namespace std; void add(int &sum, int &carry){ int a = sum ^ carry; int b = (sum & carry) > x >> y) { while (y != 0) add(x, y); cout << x << endl; } return 0;} 阅读全文
posted @ 2013-11-02 11:08 阿牧遥 阅读(229) 评论(0) 推荐(0)