看到这则新闻后觉得有点无语,这道题也难的没那么夸张,写程序的话也简单,希望媒体报道的新闻像个新闻,别什么事都当新闻报,倒是希望多报一些关于科技和经济的一些有价值的新闻。废话少说,直接上代码了。
#include<iostream> #include<stdlib.h> #include<fstream> #include<time.h> using namespace std; int main(){ fstream outfile; outfile.open("outNum.txt",ios::out); cout<<"beginnig the count"<<endl; time_t begin_time=time(0); tm tim_begin=*localtime(&begin_time); int allofNum=0,num=0; for(int a=1;a<10;a++){ for(int b=1;b<10;b++){ for(int c=1;c<10;c++){ for(int d=1;d<10;d++){ for(int e=1;e<10;e++){ for(int f=1;f<10;f++){ for(int g=1;g<10;g++){ for(int h=1;h<10;h++){ for(int i=1;i<10;i++){ int N[9]={a,b,c,d,e,f,g,h,i}; if(66==a+13*b/c+d+12*e-f-11+g*h/i-10&&(0==b%c)&&(0==g%h)){ outfile<<a<<","<<b<<","<<c<<","<<d<<","<<e<<","<<f<<","<<g<<","<<h<<","<<g<<","<<i<<endl; cout<<a<<","<<b<<","<<c<<","<<d<<","<<e<<","<<f<<","<<g<<","<<h<<","<<g<<","<<i<<endl; num++; } allofNum++; } } } } } } } } } cout<<"the end"<<endl; cout<<"the all of Num is: "<<allofNum<<endl;; cout<<"the num is: "<<num<<endl;; outfile.close(); time_t end_time=time(0); tm tim_end=*localtime(&end_time); int usetime_sec=tim_end.tm_sec-tim_begin.tm_sec; cout<<"using time "<<usetime_sec<<endl; return 0; }
从输出结果可以看出有上面的题总共有230389个解,用最基本的佛如for循环计算的话需要9秒钟时间,有错误的话希望大家指出来。
时间: 2024-10-11 22:31:03