标题:我的第一个程序,运行不出,请高手指点!写出正确的!谢谢谢谢谢谢谢谢!
取消只看楼主
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
 问题点数:0 回复次数:5 
我的第一个程序,运行不出,请高手指点!写出正确的!谢谢谢谢谢谢谢谢!
请高手指点一下,程序错在哪里,可以的话,请把正确的程序也贴上,谢谢了!
题目:
Assign in all possible ways a digit to each of the letters that occur in the words ONE, TWO, SEVEN and NINE, so that:
di fferent digits are assigned to diff erent letters;  the digit assigned to the fi rst letter of each word is not zero;  the equality ONE + ONE = TWO holds;  SEVEN is a prime number;  NINE is a perfect square.
The output of your program,, should be lines of the form
one = ..., two = ..., seven = ..... and nine = .... is a solution.

我的程序:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    for (int m=32; m<99; ++m) {
      int nine=m*m;
      int n=nine/1000;
      if (!(n%2))
      continue;
      int bits_1=1<<n;
      int i=nine/100%10;
      if (i==n)
      continue;
      bits_1+=1<<i;
        if ((bits_1>>n)%2)
          continue;
           bits_1+=1<<n;
        if ((bits_1>>i) %2)
          continue;
           bits_1+=1<< i;
        if ((bits_1>>n)%2)
           continue;
         bits_1+=1<<n;
          int e=nine%10;
          if ((bits_1>> e)%2)
            continue;
        bits_1+=1<<e;
      int o,t,w;
      int one=100*o+10*n+e;
      int two=100*t+10*w+o;
        if (one+one==two)
          continue;
          int s;
          int v;
      int seven=10000*s+1000*e+100*v+10*e+n;
      bool is_prime=true;
      int sq_root_of_seven=sqrt(seven);
       for (int k=3;k<=sq_root_of_seven;k +=2)
         if (!(seven % k)) {
                   is_prime=false;
                      break;
             }
           if (is_prime)
             printf ("one = %d, two = %d, seven = %d and nine = %d is a solution.\n",one, two, seven, nine);
    }

return EXIT_SUCCES

[[it] 本帖最后由 jasonfungsing 于 2008-4-4 20:41 编辑 [/it]]
搜索更多相关主题的帖子: NINE digit ONE 
2008-04-03 22:35
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
得分:0 
我是用emacs的,是苹果系统下的一个编译器
2008-04-03 22:48
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
得分:0 
我也有用devc++,楼上的麻烦帮忙看看吧,适合devc++也可以啊!
2008-04-03 23:08
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
得分:0 
一楼有题目啊,程序就是为了实现题目的要求啊。
2008-04-03 23:23
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
得分:0 
能给个正确的程序出来吗?谢谢啦!!
2008-04-04 09:39
jasonfungsing
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-3-29
得分:0 
9楼的高手,能给出一个正确的程序吗?谢谢啦!!!!无尽感激!!!
2008-04-04 19:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-207036-1-1.html




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

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