
字符串操作
vsooda
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDU 1228 简单题
#include using namespace std; char num[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int lookup(char *t) { for(int i = 0; i < 10; i++) if(strcmp(t,原创 2012-09-16 09:24:58 · 625 阅读 · 0 评论 -
HDU 2573 打字 (2577动态规划)
#include #include using namespace std; int main() { int t; cin >> t; while(t--) { int n; int flag = 0; char a[10]; cin >> n; while(n--) { cin >> a; if(strcmp("Caps", a) == 0)原创 2012-09-16 19:43:34 · 857 阅读 · 0 评论 -
HDU 2526 题意不好理解,用到滚动数组
题目的意思是:如题目那张图所示,下一行中间那块的颜色,由其上三块的颜色决定。 #include #include #include using namespace std; char c[2][50]; int T,val,M; int main() { char a[4],b[9]; for(int i=0;i<2;i++) c[i][0]='0'; scanf("%d",&T原创 2012-09-16 22:04:21 · 1306 阅读 · 0 评论 -
HDU 1230 火星 A + B, 进制转换
#include #include #include using namespace std; string a, b; int prim[40] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113}; int x[30], y[30]; int ma原创 2012-09-16 18:46:09 · 1421 阅读 · 0 评论 -
HDU 1982 反例
没有考虑完全,WA了一次,用-----######---##-#-#(应该输出十个空格)这个例子可以验证代码的正确性。 #include using namespace std; char str[10010]; int main() { int t; cin >> t; getchar(); while(t--) { gets(str); int n = strlen(st原创 2012-09-18 00:14:12 · 796 阅读 · 0 评论 -
HDU 1200 扭曲的题意
题意: 把一串字符竖着写成n列,得到一张表。现在横着把表的每行拼成一个字符串,其中奇数行(从0开始)反着拼。给你这个字符串求原来的加密前的字符串。 #include #include #include using namespace std; string words[21]; int main () { string str; int col; while (原创 2012-09-18 08:54:22 · 492 阅读 · 0 评论 -
HDU 1062 逆转字符串。 换行符判断使用 str[i] == '\0'
使用reverse函数, 换行符判断使用 str[i] == '\0'。 #include #include using namespace std; char str[1010]; int main() { int t; cin >> t; getchar(); while(t--) { int t = 0; while(gets(str)) { int n =原创 2012-09-22 10:16:25 · 1278 阅读 · 0 评论 -
HDU 1073 Online Judge strcat的使用,以及回车换行符的替换
#include #define N 10000 char str1[N],str2[N]; void input(char *str) { char tmp[N]; getchar(); gets(tmp); while(gets(tmp) && strcmp(tmp,"END")) { if(strlen(tmp)==0)原创 2012-09-23 19:32:31 · 1510 阅读 · 0 评论 -
HDU 1082 矩阵乘法次数计算 写了半天搞定,很有成就感啊
这个思想本来不难,实现起来感觉有点复杂,容易出错。调试了搞定。有成就感。、 #include #include #include #include using namespace std; int row[26], col[26]; char str[10000]; int count(int *a, int n) { int flag = 0; if(n == 2) retur原创 2012-09-24 15:05:09 · 1367 阅读 · 0 评论 -
HDU 1753 大数 strchr
#include #include int a[1010],b[1010],sum[1010]; char str[1010]; int main() { int i,j,k,n,s,c; while(scanf("%s",str)==1) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(sum,0,sizeof(su原创 2013-01-18 16:44:15 · 590 阅读 · 0 评论 -
HDU 4513 回文串Manacher算法
Manacher算法学习: http://blog.youkuaiyun.com/vsooda/article/details/8725580 代码1:转自http://blog.youkuaiyun.com/sprintfwater/article/details/8709458 #include #include #include #define MAXN 100005 int a[MAXN * 2]; s转载 2013-03-27 19:40:21 · 1849 阅读 · 0 评论 -
HDU 2054 字符串 比较两个数大小,忽略整数前面的0和小数最后的0
猜也能猜到,本题的数据不可能是简单到直接能保存进整型里。 它可能有10000位的长度,所以需要保存到字符串里。 比较的时候,需要注意的是:像0001.00与1是相同的。 #include #include void A(char *s) { int len = strlen(s); char *p = s + len - 1; if (strchr(s, '.')) wh原创 2012-09-14 11:01:18 · 1078 阅读 · 0 评论 -
HDU 1088 处理每个字符串比直接用getchar处理简单
原本用getchar处理,很难达到语气目标。用字符串就简单多了 #include #include #include int main() { char html[1000]; int len=0; while(scanf("%s",html)!=EOF) { if(strcmp(html,"")==0) { len=0; printf("\n"); } el原创 2012-09-13 15:22:33 · 806 阅读 · 0 评论 -
ZJU 1115 新形式
#include int main() { char ch; while(1) { int sum=0; while(scanf("%c",&ch) && ch!='\n') { sum+=ch-'0'; } if(sum==0) break; if(sum%9==0) sum=9; else sum=sum%9; printf("%d\n",sum); }原创 2012-02-16 20:30:30 · 413 阅读 · 0 评论 -
ZJU 1105 从缓冲读入
#include #include double distance(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { double x0,y0; double x1,y1,x2,y2; char stree原创 2012-02-16 20:22:24 · 507 阅读 · 0 评论 -
ZOJ 1151
#include #include char line[1000]; int main() { int n,m,len,i,j,k; scanf("%d",&n); while(n--) { scanf("%d\n",&m);//注意此处的\n表示忽视输入的回车,直到输入别的字符后才继续往下 while(m--) { gets(line); len=strlen(line原创 2012-02-16 21:43:18 · 1146 阅读 · 0 评论 -
HDU 2072 单词统计
#include #include #include #include using namespace std; int main() { set st; string s=""; char c; while((c=getchar())!='#') { s+=c; while(c!='\n') { while((c=getchar())!=' '&& c!='\n')原创 2012-02-18 19:31:42 · 573 阅读 · 0 评论 -
HDU 2087 strstr
strstr 语法: #include char *strstr( const char *str1, const char *str2 ); 功能:函数返回一个指针,它指向字符串str2 首次出现于字符串str1中的位置,如果没有找到,返回NULL。 #include #include int main(void) { int len, c; c转载 2012-02-19 10:42:41 · 517 阅读 · 0 评论 -
HDU 2089
#include int A(int n) { int i = 1; while (n) { if (n % 10 == 4 || n % 100 == 62) return i; n /= 10; i *= 10; } return 0; }转载 2012-02-19 11:00:01 · 653 阅读 · 0 评论 -
HDU 2093
#include #include int main() { int n,m,i=0,j,k,t,rs; char s[1000][11],c; int a[12][2],cnt[1000],sum[1000],sooda[1000]={0}; scanf("%d%d%*c",&n,&m); while(scanf("%s",s[i])!=EOF) { sum[i]=0; c原创 2012-02-19 18:02:33 · 521 阅读 · 0 评论 -
HDU 2094 拓扑
#include #include #include #include using namespace std; int main() { freopen("2094.txt","r",stdin); int n,i,t; string b,e; sets; set::iterator it; mapm; map::iterator iter; while(cin>>n转载 2012-02-19 18:23:51 · 477 阅读 · 0 评论 -
HDU 1075 用gets可以获取字符串输入的空格回车等。以后用字典树尝试提高效率
#include #include #include #include using namespace std; int main() { freopen("1075.txt", "r", stdin); string first; string second; cin >> first; map word; while(cin >> first, first != "END原创 2012-09-09 10:12:40 · 701 阅读 · 0 评论 -
各种字符串Hash函数比较
常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法。这些函数使用位运算使得每一个字符都对最后的函数值产生影响。另外还有以MD5和SHA1为代表的杂凑函数,这些函数几乎不可能找到碰撞。 常用字符串哈希函数有BKDRHash,APHash,DJBHash,JSHash,RSHash,SDBMHash,PJWHash,ELFHash等等。对于以上几种哈希函数,我对转载 2012-09-26 10:12:51 · 593 阅读 · 0 评论 -
Manacher算法--O(n)回文子串算法
这里,我介绍一下O(n)回文串处理的一种方法。Manacher算法. 原文地址: http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/ 其实原文说得是比较清楚的,只是英文的,我这里写一份中文的吧。转载 2013-03-27 11:11:36 · 840 阅读 · 0 评论