歡迎辭歡迎來到“篤志以礪,決起而飛”! 如果您是第一次來到本站,建議訪問 本站導讀以便更快地了解本站。 如果您喜歡本站, 歡迎訂閱。 | 這個程序是哈爾濱工業大學的一道作業題,有一位朋友昨晚讓我看了這道題目,我發現這道題目還真不是那麼簡單。學校對剛剛學完數組的大一同學出此題目是否欠妥呢? 現在先看看題目。 Prime Palindromes
The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (5 <= a < b <= 100,000,000); both a and b are considered to be within the range . 閱讀全文 » 寫在前面:進入武漢大學以來,我最大的感受就是忙。各種各樣的事情讓人奔波不停,繁忙的生活似乎永遠沒有盡頭。有時候,我突然有一段時間沒有事情做,我會感到非常地不可思議,甚至有些恐慌。各種講座、學術會議琳琅滿目。繁忙,或許是每個這裡的學生共同的體會。課表排滿了週一到週五,各種實踐活動、比賽和社團活動充滿了課餘時間,而大家又都在不斷的發展自己的才藝和特長。但是我特別喜歡這種感覺,這樣過去的每一天都會感到很充實。 大學入學以來,我已經逐漸認識了很多人,新的人際關係也開始逐漸建立。事情和人際忙的不可開交,我有時候會忙到沒空學自己感興趣的知識、沒空讀書、沒空寫博客、沒空吃飯、沒空洗澡、沒空睡覺……在這種情況下,本文的出現可以說是一個奇蹟。 閱讀全文 » Internet is a computer network that connects millions of computers across a number of countries. There is no central authority that controls the Internet; different organizations own different pieces of it. The Internet was originally conceived of by the Advanced Research Project Agency (ARPA) of the U.S. government in the 1960s. The World Wide Web (or "the Web" for short) refers to that portion of the computers on the Internet that can communicate with each other using a computer-network protocol called HTTP. All browsers use HTTP to request and receive Web pages from other computers. We have used the words page and place interchangeably when referring to the Web. Another synonymous term is site, as in Web site. All three terms refer to locations on the Web that you can visit and view through a browser. An Internet Service Provider (ISP) is any one of a number of companies that enable people like you and me not only to connect to the Internet and surf the Web but also to publish Web pages. There is no one to certify that the information presented on the Web is accurate<精確的>, correct, and up-to-date. A search engine is a program that allows one to search for keywords in files at one or more Internet sites. Popular search engines include Lycos, Excite, and AltaVista. Time goes by, I have been in International Software School of Wuhan University for my college for some days. My dream is to be a good programmer, a software architect, even aa boss of a IT company. I know it is so important to learn English for my major, for I will always have much time reading English articles, and may go to foreign countries for further study. In high school, I have learned much English knowledge. In my opinion, I am not to study only the grammer or the word. As for my expectation for this term, I select a word called ENJOY. So I plan to learn more than English itself. English culture, knowledge written in English language, and even everything else in English, will be my expectation. With my growing up, I have realized that to learn is not only to get the knowledge, but also to gain the feeling of culture. I remember,when I study Chinese, I usually want to get the cultural background of the text. I also want to learn more about English culture in my subject. For this reason, I will read much more. I want to start my morning-reading. I can not wait to sit in the picturesque university, reading aloud, making myself fly to the western countries. Enjoy the sunshine, the article, the happiness of learning English, and make a beautiful trip to everywhere in the world. How eagerly I expect it! Read more, do more morning-reading, and listen more. I believe I will gain my sense of English which is my biggest target in this term. I will also know more about English culture. (IT IS MY HOMEWORK FOR COLLEGE ENGLISH, EDITED WITH NAL’S HELP. THANKS) 這道題目沒有花費什麼時間,基本上寫完就 AC 了,不過在這道題目上倒是認識到一個問題。 函數 itoa, atoi 等並非標準的 C 函數庫擴展,在很多網站上大量濫用這些函數,但這些函數只能用於 VC++ 等編譯器。在 G++ 等編譯器中是不適用的。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
| /*
ID: cxj6661
LANG: C++
PROG: crypt1
*/
#include <fstream>
#include <string>
#include <stdio.h>
#include <memory.h>
using namespace std;
const char *infile = "crypt1.in";
const char *oufile = "crypt1.out";
bool can[10]; // define whether the number is used.
int use[5];
int l, res = 0;
// ** function declare **
bool check();
bool allin(char *s);
// change int into char* type.
#define tostr(d,to) \
{ \
sprintf(to, "%d", d); \
}
inline void init() // read file.
{
memset(can, false, sizeof(can));
ios::sync_with_stdio(false);
ifstream fin(infile);
fin >> l;
for (int i = 0, j; i < l; ++i)
{
fin >> j;
can[j] = true;
}
fin.close();
}
inline void doit(int p) // dfs.
{
if (p == 5) // has found a result of two numbers.
{
if (check())
++res;
return;
}
for (int i = 0; i < 10; ++i)
if (can[i])
{
if ((p == 0 || p == 3) && i == 0)
continue;
use[p] = i;
doit (p+1);
}
}
inline bool check() // check whether it's a good result.
{
int a = use[2] + use[1] * 10 + use[0] * 100, b = use[3] * 10 + use[4],c = a * use[4], d = a * use[3];
if (c > 999 || d > 999 || c < 100 || d < 100)
return false;
char s1[10], s2[10];
tostr(c, s1);
tostr(d, s2);
if ((!allin(s1)) || (!allin(s2)))
return false;
int e = c + d * 10;
if (e > 9999 || e < 1000)
return false;
tostr(e, s1);
if (!allin(s1))
return false;
return true;
}
inline bool allin(char *s) // is all number in the can array?
{
for (int i = 0; i < strlen(s); ++i)
{
if (!can[s[i] - '0'])
{
return false;
}
}
return true;
}
inline void output() // output the result.
{
ofstream fout(oufile);
fout << res << endl;
fout.close();
}
int main(void)
{
init();
doit(0);
output();
return 0;
} |
| |
近期評論