循环报数
2015-08-13 23:08
288 查看
#include<iostream> #include<string> using namespace std; class node { public: char c; node*next; }; node* insert(char*list,int length) { int i=0; node*first; node*pre; while(i<=length-1) { node *temp=new node; temp->c=list[i]; if(i==0) { first=temp; pre=temp; } else if(i==length-1) { pre->next=temp; pre=temp; temp->next=first; } else { pre->next=temp; pre=temp; } i++; } return first; } void baoshu(node*first,int m,int length,char*result) { node*cur=first; node*pre=first; int i=1; int k=0; while(k!=length-1) { i=1; while(i!=m) { pre=cur; cur=cur->next; i++; } node*temp=cur->next; pre->next=cur->next; result[k]=cur->c; delete cur; cur=NULL; cur=temp; k++; } result[k]=cur->c; delete cur; cur=NULL; result[length]='\0'; } int main() { int m; cin>>m; char a[1000]; char c; int i=0; while(cin>>c) { a[i]=c; i++; if(cin.get ()=='\n') break; } node* first=insert(a,i); char result[1000]; baoshu(first,m,i,result); cout<<result; }
相关文章推荐
- iOS设计模式---命令模式
- 自定义 URL Scheme 完全指南
- opencv特征提取
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- iOS开发篇——OC之面向对象的三大特征
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- 黑马程序员———面向对象之包、访问修饰符、内部类
- scala 选择排序 冒泡排序
- 使用ViewPager实现可以自动切换的广告控件
- 非递归排序(冒泡、选择、插入、希尔)
- CSS学习总结
- swift-07-使用for-in 遍历数组
- swift-08-元组分解和数组
- (一)XML简介
- swift-07-使用for-in 遍历数组
- swift-08-元组分解和数组
- cocos2dx 做test遇到一个问题,记录下来
- ZOJ 3692
- 32位和64位系统区别及int字节数
- 实现maven nexus 安装