| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 751 人关注过本帖
标题:大家都来做诗人,分享一下
取消只看楼主 加入收藏
tianhe
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2005-3-17
收藏
 问题点数:0 回复次数:1 
大家都来做诗人,分享一下

using System; using System.Collections; class poem { public static string[] poem1=new string[]{"尊敬的","可爱的","慈祥的","亲爱的","调皮的","活泼的","深沉的","可恶的","讨厌的","烦人的","高贵的","自恋的", "大胆的","心细的","懒惰的","爱美的","时尚的","前卫的","保守的","固执的","灵活的","轻巧的","迷人的","漂亮的","多情的","伤感的","善感的"}; public static string[] poem2=new string[]{"太阳","月亮","星星","牦牛","鳄鱼","毛驴","小草","梅花","苹果","香蕉","橘子","汉包","热狗","露水","晨雾","夕阳","紫烟","瀑布","岩石","飞机","隧道","天空","猎狗","大象","黑熊","柴狗","企鹅"}; public static string[] poem3=new string[]{"爱","恨","等","看","愣","瞪","笑","哭","打","骂","催","找","盼","吵","缠","追","赶","跑","跳","望","窥","瞧","瞟","扫","钓","瞻","视"}; public static void Main() { Print(); } static void Print() { Random r=new Random(); Console.WriteLine("input numbers"); int a=int.Parse(Console.ReadLine()); for(int i=0;i<a;i++) { bool b=true; while(b) { string str1=poem1[r.Next(poem1.Length)]; string str2=poem2[r.Next(poem2.Length)]; string str3=poem3[r.Next(poem3.Length)]; string str4=poem2[r.Next(poem2.Length)]; if(str2!=str4) { Console.WriteLine("{0},{1}",i+1,str1+str2+str3+str4); break; } else { continue; } } }

} }

搜索更多相关主题的帖子: 诗人 分享 
2005-04-13 17:33
tianhe
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2005-3-17
收藏
得分:0 

对不起各位,忘了写注释,犯了一个致命的错误,请原谅。请多提建议 using System; using System.Collections; class poem { //如果想让诗更有意思,可以把数组中的词改改。 public static string[] poem1=new string[]{"尊敬的","可爱的","慈祥的","亲爱的","调皮的","活泼的","深沉的","可恶的","讨厌的","烦人的","高贵的","自恋的", "大胆的","心细的","懒惰的","爱美的","时尚的","前卫的","保守的","固执的","灵活的","轻巧的","迷人的","漂亮的","多情的","伤感的","善感的"}; public static string[] poem2=new string[]{"太阳","月亮","星星","牦牛","鳄鱼","毛驴","小草","梅花","苹果","香蕉","橘子","汉包","热狗","露水","晨雾","夕阳","紫烟","瀑布","岩石","飞机","隧道","天空","猎狗","大象","黑熊","柴狗","企鹅"}; public static string[] poem3=new string[]{"爱","恨","等","看","愣","瞪","笑","哭","打","骂","催","找","盼","吵","缠","追","赶","跑","跳","望","窥","瞧","瞟","扫","钓","瞻","视"}; public static void Main() { Print(); } static void Print() { Random r=new Random(); Console.WriteLine("input numbers");//要做的诗的行数,如果输入5,显示5行诗 int a=int.Parse(Console.ReadLine()); for(int i=0;i<a;i++) { bool b=true; while(b) { //把数组中的元素赋给一个字符型变量,是为了防止出现同一行中有重复的词组,比如:可爱的苹果爱苹果 string str1=poem1[r.Next(poem1.Length)]; string str2=poem2[r.Next(poem2.Length)]; string str3=poem3[r.Next(poem3.Length)]; string str4=poem2[r.Next(poem2.Length)];//这是为省事把第二个数组用了两次。 if(str2==str4) { Console.WriteLine("{0},{1}",i+1,str1+str2+str3+str4); break; } else { continue;//如果判断出str2中的词组和str4的词组相同则跳出 } } }

} }


-------------------------------------------- 朴素,清醒
2005-04-13 17:54
快速回复:大家都来做诗人,分享一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021828 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved