三色旗问题
来源:互联网 发布:中国男演员演技知乎 编辑:程序博客网 时间:2024/05/01 20:18
package coding;public class cha09_flag { static int count; static char color[]="rwbwwbrbwr".toCharArray(); static int Blue,White,Red; static void swap(char[] c,int x,int y){ int i; char temp; temp=c[x]; c[x]=c[y]; c[y]=temp; count++; System.out.println("第"+count+"次对调后"); for(i=0;i<color.length;i++){ System.out.print(color[i]+" "); } System.out.println(); } static void threeflags(){ while(color[White]=='b'){ Blue++; White++; } while(color[Red]=='r'){ Red--; } while(White<=Red){ if(color[White]=='r'){ swap(color,White,Red); Red--; while(color[Red]=='r'){ Red--; } } while(color[White]=='w'){ White++; } if(color[White]=='b'){ swap(color,White,Blue); Blue++; White++; } } } public static void main(String[] args) { // TODO Auto-generated method stub int i; Blue=0; White=0; Red=color.length-1; count=0; System.out.println("三色旗问题求解"); System.out.println("三色旗最初排列效果"); for(i=0;i<=Red;i++){ System.out.print(color[i]+" "); }System.out.println(); threeflags(); System.out.println("通过"+count+"次排列后的效果"); for(i=0;i<color.length;i++){ System.out.print(color[i]+" "); }System.out.println(); }}
0 0
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗排序问题
- 三色旗排序问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗问题
- 三色旗的问题
- 三色旗问题
- 三色旗问题的解决
- Algorithm Gossip:三色旗问题
- 三色问题
- 关于MySQL由于外键约束而无法执行删除操作的一个简单的解决办法
- connect、resource角色的演变和Oracle权限简介
- iOS 实现电话号的星号加密
- AlarmManager 使用小结
- 安卓布局 - 线性布局(LinearLayout)
- 三色旗问题
- 关于转义字符 \t \r \n
- 452. Minimum Number of Arrows to Burst Balloons
- 利用EXCEL将多列多行数据转换为SQL语句【新增、删除、修改同理】
- javascript 封装
- iOS-裁剪图片
- 使用TP上传类,一个表单多个file上传丢失部分文件
- js获取鼠标位置
- Cordova自带webview的cookie自动同步问题,和引入crosswork插件后cookie自动同步问题的解决