Broken Necklace 坏掉的项链
来源:互联网 发布:苹果手机如何抹除数据 编辑:程序博客网 时间:2024/04/29 07:49
#include <iostream>#include <string>#include <stdlib.h>#include <stdio.h>using namespace std;struct node{char c;struct node * next;struct node * prev;};int main(int argc, char const *argv[]){cout<<"Please input ?"<<endl;char c;c = getchar();struct node *head,*first,*p,*tail,*q,*t;head = (struct node*)malloc(sizeof(struct node));first = head;head->c = c;head->next = NULL;head->prev = NULL;c = getchar();while(c!= '!'){p = (struct node*)malloc(sizeof(struct node));head->next = p;p->next = NULL;p->prev = head;p->c = c;head = p;c = getchar();}tail = head;head->next = first;first->prev = head;// head = first->next;// cout<<first->c;// while(head!=first)// {// cout<<head->c;// head = head->next;// }// head = first->prev;// while(head != first)// {// cout<<head->c;// head = head->prev;// }// cout<<first->c;int max = 0;for(p=first;p!=tail;p=p->next){int left = 1;if(p->c == 'b'){q = p->prev;while(q->c == 'b' or q->c =='w'){left++;q = q->prev;}}else if(p->c == 'r'){q = p->prev;while(q->c == 'r' or q->c == 'w'){left++;q = q->prev;}}else{int b = 1;int r = 1;q = p -> prev;t = p -> prev;while(q->c == 'b' or q->c == 'w'){b++;q = q->prev;}while(t->c == 'r' or t->c == 'w'){r++;t = t->prev;}if(b-r >= 0)left = b;elseleft = r;}int right = 1;if(p->next->c == 'b'){q = p->next->next;while(q->c == 'b' or q->c == 'w'){right++;q = q->next;}}else if(p->next->c == 'r'){q = p->next->next;while(q->c == 'r' or q->c == 'w'){right++;q = q->next;}}else{int b = 1;int r = 1;q = p->next->next;t = p->next->next;while(q->c == 'b' or q->c == 'w'){b++;q = q->next;}while(t->c == 'r' or t->c == 'w'){r++;t = t->next;}if(b-r >= 0)right = b;elseright = r;}int temp;temp = left + right;cout<<temp<<endl;if(temp >= max)max = temp;}cout<<max<<endl;return 0;}
0 0
- Broken Necklace 坏掉的项链
- [USACO1.1.4]坏掉的项链Broken Necklace
- USACO——Broken Necklace 坏掉的项链
- |洛谷|模拟|P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 【P1203】 【USACO1.1】坏掉的项链Broken Necklace
- 【搜索】洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 洛谷 1203 [USACO1.1]坏掉的项链Broken Necklace
- Broken Necklace破碎的项链
- Broken Necklace破碎的项链
- usaco1.1.4 Broken Necklace破碎的项链
- USACO1.1.4 Broken Necklace(破碎的项链)
- USACO1.1.4 Broken Necklace 破碎的项链
- Broken Necklace-----破碎的项链----USACO---C1S1
- 坏掉的项链
- Codility-CountNonDivisible
- android基础笔记:获取网页HTML代码
- Java6 WebService的发布
- Luxand FaceSDK配置详解
- hadoop不同版本之间的集群复制
- Broken Necklace 坏掉的项链
- ios label 重绘《一》(画线和文字)
- 杭电ACM2043 密码-----20140730
- JQuery 只能输入数字
- HDFS的运行原理
- 母函数
- JAVACV内存泄漏,std::exception: bad allocation
- 描述类和结构的知识
- hibernate.cfg.xml的配置