我的第一个程序,运行不出,请高手指点!写出正确的!谢谢谢谢谢谢谢谢!
请高手指点一下,程序错在哪里,可以的话,请把正确的程序也贴上,谢谢了!题目:
Assign in all possible ways a digit to each of the letters that occur in the words ONE, TWO, SEVEN and NINE, so that:
different digits are assigned to different letters; the digit assigned to the first 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]]