| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 302 人关注过本帖
标题:有个好问题,帮忙分析一下!!!
只看楼主 加入收藏
dandanbaobei
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-2-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
有个好问题,帮忙分析一下!!!

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int woshu,
        jishu,
        xhwo,
        xhji,
    //    jige,
    //    jiwei,
        wei;
    int f1=0,
        f2=0,
        f3=0,
        f4=0,
        jige=0,
        jiwei=0;
   
    srand((unsigned int)time(NULL));
    jishu = rand()%9000+1000;                       
//    printf("%d 输入一个数:",jishu);                    //不加这个猜的难度加大了点
    scanf("%d",&woshu);
    while(woshu!=jishu)
    {
                f1=f2=f3=f4=0;                        
                jige=0;
                jiwei=0;

        for(xhwo=1000;xhwo>=1;xhwo=xhwo/10)
        {
            for(wei=1,xhji=1000;xhji>=1;wei++,xhji=xhji/10)
                                                                    
            {                                                        
                                                                    
                if(woshu/xhwo%10 == jishu/xhji%10)
                {
                    switch(wei)
                    {
                    case 1:
                        if(0==f1)
                        {
                            jige++;
                            f1=1;
                            break;
                        }
                        break;
                    case 2:
                        if(0==f2)
                        {
                            jige++;
                            f2=1;
                            break;
                        }
                        break;
                    case 3:
                        if(0==f3)
                        {
                            jige++;
                            f3=1;
                            break;
                        }
                        break;
                    case 4:
                        if(0==f4)
                        {
                            jige++;
                            f4=1;
                            break;
                        }
                        break;
                    }
                }
            }
        }
        for(xhwo=1000;xhwo>=1;xhwo=xhwo/10)
        {
            if(woshu/xhwo%10==jishu/xhwo%10)
            {
                jiwei++;
            }
        }
        printf("有%d个相等的\n",jige);
        printf("有%d位相同\n",jiwei);
        printf("在输入一个数:");
        scanf("%d",&woshu);
   
    }
    printf("你赢了\n");

    return 0;
}
这个程序有点瑕疵,运行的准确率有点低啊,帮忙改一下,悉心听取!
搜索更多相关主题的帖子: include 
2012-02-20 19:52
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:10 
我觉得你应该简单的描述一下这个问题吧?

My life is brilliant
2012-02-20 19:58
真的很菜
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:94
专家分:151
注 册:2012-2-18
收藏
得分:10 
看不懂
2012-02-21 18:03
快速回复:有个好问题,帮忙分析一下!!!
数据加载中...
 
   



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

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