ZOJ-2240
来源:互联网 发布:大数据安全与隐私保护 编辑:程序博客网 时间:2024/06/06 17:37
我吐血啊。。本来这题字符串处理就挺恶心的,好不容易感觉上已经逻辑对了,结果一直WA。。最后只能跑去查原题的input和output,还好这题是以前的国际竞赛题,可以查找,最后发现是挂在了空行上!!!真是坑死人不偿命啊,诶,说到底还是粗心,那种不断提交一直WA的心情,是广大ACMer心中永远的痛。。
#include<stdio.h>#include<string.h>void printBuffer(char *s, int total){ if (total == 0) return; putchar('1'); int i; for (i = 0; i < total; i++) if (s[i] == '1') printf("11"); else putchar(s[i]); putchar('1');}void printSame(int count, char c){ printf("%d", count); putchar(c);}int main(){ char s[1024]; while (gets(s) != NULL) { if (strlen(s) == 0) { putchar('\n'); continue; } char buffer[1024]; int i, prev = s[0], index = 0, count = 1; buffer[index++] = prev; for (i = 1; s[i] != '\0'; i++) { if (s[i] == prev) { if (index > 0 && buffer[index - 1] == s[i]) { printBuffer(buffer, index - 1); index = 0; } count++; } else { if (count != 1) { while (count > 9) { printSame(9, prev); count -= 9; } if (count == 1) buffer[index++] = prev; else printSame(count, prev); } buffer[index++] = s[i]; count = 1; } prev = s[i]; } if (count != 1) { while (count > 9) { printSame(9, prev); count -= 9; } if (count == 1) { putchar('1'); if (prev == '1') printf("11"); else putchar(prev); putchar('1'); } else printSame(count, prev); } else printBuffer(buffer, index); putchar('\n'); } return 0;}
0 0
- ZOJ-2240
- poj 2240 &zoj 1092
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- Leetcode: Anagrams
- [cocos2d-x]对CCSprite进行高斯模糊
- HDU 1062(水题)
- 在Ubuntu上使用vsftpd搭建FTP服务器
- secureCRT给我加了个0D
- ZOJ-2240
- VS2005 添加右键快捷菜单
- HDU 1064(水题)
- easymock单元测试实例二
- c# 读xml文件
- WinCE驱动编写小结
- wxListCtrl的基本用法
- C与C++的兼容问题——extern "C"的用法解析
- leetcode_Evaluate Reverse Polish Notation