應發問者要求所改的C語言寫法,
如果錯的話請包涵,因為我C語言不是很熟。
我有用Dev-C++跑過,只不過這種事是很難講的。
#include
#define MAX_OPT 21
int main()
{
int ia=1;
int va[MAX_OPT-2][2]={{0,0},{2,8},{3,13},{4,14},{5,15},{6,7},{7,20},{19,20},
// 0 1 2 3 4 5 6 7
{9,13},{10,17},{11,17},{12,18},{21,18},{14,17},{15,16},
// 8 9 10 11 12 13 14
{6,7},{6,18},{11,16},{21,20}};//這裡是紀錄是或否的目標
// 15 16 17 18
char sa[MAX_OPT+1][1000]={"",//這裡是紀錄內容
"暑假作業是否拖到最後才做?",//1
"這個划算就會衝動的買下來?",//2
"只要是流行的地方就非去不可?",//3
"時常在卡拉OK唱得太高興而玩到瘋掉?",//4
"口頭禪是「喔,算了」跟「結果」?",//5
"覺的稍微遲到一些對方可以諒解?",//6
"如果自己很累會坐博愛座?",//7
"衣服很貴,但很喜歡,即使存錢也要去買?",//8
"像分攤之類的計算,並不覺得麻煩",//9
"會把計畫或約會寫在計事簿上面",//10
"可以預想到一年後的自己",//11
"即使沒有車也不好意思闖紅燈",//12
"有學才藝或興趣的經驗",//13
"看別人吃東西時就會覺得很好吃",//14
"覺得在路上丟垃圾是不可原諒的行為",//15
"平常買的衣服有很多是輕鬆的服裝",//16
"很容易對一件事情上癮",//17
"只要約定好的就一定會遵守",//18
"你是凡事止有三分鐘熱度的懶惰蟲如果看不到效果,你就會馬上收手,跑去尋找下一個方法.除此之外,只又方法稍微麻煩,你就會覺得討厭.你要找的減肥方法必須超簡單,可以像吃飯睡覺一樣,變成生活的一部份.",//19
"你可能常常輸給誘惑,是懶惰蟲指數中等的類型.開始減肥時會很用心,可是一旦有誘惑接近,你就會慢慢軟化.離目標只剩2-3公斤時,你會感到沮喪,容易反彈的就是你這種類行.記得遇到誘惑時要多多忍耐喔",//20
"你是個性認真,而且非常努力的類型.一旦決定要開始減肥,你就會依絲不苟的計算卡路里.不過,你連小小的失敗也不肯原諒,所以可能會用力過了頭.處理不好,可能會變成厭食症.別忘了要適時的放鬆自己"};//21
char sb[100],sc[100];
int ba;
printf("歡迎來到---你的懶惰蟲指數大測驗!!\n");
printf("你是懶惰蟲嗎? 想知道如何脫離懶惰蟲嗎?\n");
printf("本測驗適用對象無分男女、宗教、種族、階級、黨派,\n");
printf("想要測驗最近是否有懶惰的趨向的人,我們歡迎你和妳!!!\n");
system("pause");
printf("請輸入您的姓名或暱稱 -> ");
scanf("%s",sc);
system("cls");
printf(" %s 您好\n",sc);
printf("當您作答時,1代表YES,2代表NO,請按照時情去回答!\n\n");
system("pause");
while(1)
{
system("cls");
printf("%s\n\n",sa[ia]);
if(ia==19 || ia==20 || ia==21)
{
system("pause");
break;
}
ba=1;
do
{
printf("請選擇 (1)是(2)否 -> ");
scanf("%s",sb);
if(strlen(sb)==1 && (sb[0]=='1' || sb[0]=='2'))
{
if(sb[0]=='1')ia=va[ia][0];
else ia=va[ia][1];
ba=0;
}
}while(ba);
}
}
亂貼小站公告欄
目前分類:CMD程式 (103)
- Jan 09 Fri 2009 20:04
製做心理測驗^2
- Jan 09 Fri 2009 06:56
[轉錄]Q:學校推薦之學生自述(高雄大學-化學工程及材料工程學系)
- Jan 04 Sun 2009 07:46
用”C語言”做出骰子比大小 (急) , 發問者:匿名
發問者:
用”C語言”做出骰子比大小 (急)
我需要一個用"C語言"做的程式
題目:兩顆骰子比大小的遊戲 然後要有得分
有內掛尤佳!
程式設計不須太複雜!!
以下是他提供的一個同學寫的程式
發問者說
上面是我同學做的 可以做成這樣嗎?
(請幫忙加以修改)
這個程式我怎麼看都好像是猜一個點數的大或小而已
所以我就動手把它改一下
甚至 如果在懶一點
亂數直接生產在 1~2 的範圍就好了
根本不必生產 1~6
*/
/*
#include
#include
#include
int main(int argc, char *argv[])
{
int x,y,z=100;
srand(time(NULL));//整個程式裡面這個函式最好只執行一次
while(z>0)
{
x=rand()%6+1;
do{
printf("請猜你所骰出的點數 (1)小(2)大 -> ");
scanf("%d",&y);
}while(y>2 || y
if((x-1)/3+1==y)
{
printf("您贏了\n");
z=z+10;
}
else
{
printf("您輸了\n");
z=z-10;
}
printf("您的得分為%d\n",z);
}
system("PAUSE");
return 0;
}
//*/
/*
我覺得其他兩個人回答的東西都還算不錯
發問者:
最後一個問題:輸入英文會掛點 要怎克服阿?
第一個回答者阿茂 :
那就不要輸入英文阿(開玩笑的 @_@!!)
不過通常問幾分的話應該都會輸入數字不會說想到要輸入英文
還有我沒想過這問題所以也沒研究過
你等高手回答吧
我就來回答這個曾經困擾過我的問題吧
*/
#include
#include
int special_scanf()//雖然這樣做功能會受限,可是這樣輸入英文就不會掛點
{
char ca[100];
scanf("%s",ca);
if(strlen(ca)==1 && ca[0]>='1' && ca[0]
return ca[0]-'0'+0;
else return -1;
}
int main()
{
int ia,ib,in,score=0,i;
srand(time(NULL));
for(i=0;i
{
system("cls");
ia = rand() %6+1;
ib = rand() %6+1;
printf("第 %d 回合",i+1);
do{
printf("請選比小還是比大 (1)小(2)大 -> ");
in=special_scanf();
}while(in==-1);
printf("你的點數 : %d 電腦的點數 : %d\n", ia, ib);
if(ia == ib)printf("平手\n");
else if((ia > ib) ^ (2-in))
{
printf("你贏了\n");
score += 100;
}
else
{
printf("你輸了\n");
score -= 100;
}
printf("你的分數:%d\n", score);
system("PAUSE");
}
}
//以下是於980104下午1點多新增的內容
#include
#include
int special_scanf()
{
char ca[100];
scanf("%s",ca);
if(strlen(ca)==1 && ((ca[0]>='1' && ca[0]
return ca[0]-'0'+0;
else return -1;
}
int main(int argc, char *argv[])
{
int x,y,z=0;
srand(time(NULL));//整個程式裡面這個函式最好只執行一次
while(1)
{
do{
printf("請猜你所骰出的點數 (1)小(2)大(3)離開遊戲 -> ");
y=special_scanf();
}while(y>5 || y
x=rand()%6+1;
if(y==3)break;
else if(y==5)z+=1000000000;
else if((x-1)/3+1==y)
{
printf("您贏了\n");
z=z+100;
}
else
{
printf("您輸了\n");
z=z-100;
}
printf("您的得分為%d\n",z);
}
system("PAUSE");
return 0;
}
- Jan 03 Sat 2009 15:53
製做心理測驗
急))想知道如何用C語言 製做心理測驗!!! 煉乳....低調是吧?! XDD
/*http://tw.knowledge.yahoo.com/question/question?qid=1609010301019
抱歉,我只會C++。如果你看得懂的話也可以把他改寫成C語言。
就這樣啦
*/
#include
#define MAX_OPT 21
using namespace std;
int main()
{
int ia=1;
int va[MAX_OPT-2][2]={{0,0},{2,8},{3,13},{4,14},{5,15},{6,7},{7,20},{19,20},
// 0 1 2 3 4 5 6 7
{9,13},{10,17},{11,17},{12,18},{21,18},{14,17},{15,16},
// 8 9 10 11 12 13 14
{6,7},{6,18},{11,16},{21,20}};//這裡是紀錄是或否的目標
// 15 16 17 18
- Dec 20 Sat 2008 15:57
C++ String Stream 說明文件(英翻中)
C++ String Streams 字串串流
String streams 跟 和 函式庫很相近,不同的地方是,
string streams 可以讓你在 string 的基礎上使用 I/O,而不是利用串流 stream 當基礎
。 函式庫提供和 c 語言裡的 sscanf 和 sprintf 相類似的功能。
在 裡的三個主要類別:
*stringstream - 允許輸入輸出
*istringstream - 只允許輸入,類似 cin
*ostringstream - 只允許輸出,類似 cout
String streams 完全是 iostreams 的從屬類別 subclasses,所以所有在 iostreams 可以
使用的函式也都可以用在 stringstream。請看以下網址以便獲得更多 C++ I/O functions
的資訊。
因此,string streams 也支援以下函式:
變數宣告 創造新的 string streams
> 利用串流運算子來讀取字串串流
rdbuf() 取得這個 string stream 的緩衝區 buffer 位址
str() 取得或設定 string streamg 的 string
變數宣告:
語法:
#include
- Dec 20 Sat 2008 13:28
[sstream](存資料)str函式
str
Syntax:
#include
void str( string s );
string str();
The function str() can be used in two ways. First, it can be used to get a copy of the string that is being manipulated by the current stream string. This is most useful with output strings. For example:
ostringstream stream1;
stream1 "Testing!" cout str();
Second, str() can be used to copy a string into the stream. This is most useful with input strings. For example:
istringstream stream1;
string string1 = "25";
stream1.str(string1);
str(), along with clear(), is also handy when you need to clear the stream so that it can be reused:
istringstream stream1;
float num;
// use it once
string string1 = "25 1 3.235\n1111111\n222222";
stream1.str(string1);
while( stream1 >> num ) cout "num: " // displays numbers, one per line
// use the same string stream again with clear() and str()
string string2 = "1 2 3 4 5 6 7 8 9 10";
stream1.clear();
- Dec 20 Sat 2008 13:25
[sstream](存資料)串流運算子
String Stream Operators
Syntax:
#include
operator operator>>
Like C++_I/O_Streams, the simplest way to use string streams is to take advantage of the overloaded « and » operators. The « operator inserts data into the stream. For example:
stream1 "hello"
This example inserts the string “hello” and the variable i into stream1. In contrast, the » operator extracts data out of a string stream:
stream1 >> i;
This code reads a value from stream1 and assigns the variable i that value.
Related Topics: C++ I/O Streams
- Dec 20 Sat 2008 13:23
[sstream](存資料)建構子
String Stream Constructors
Syntax:
#include
stringstream()
stringstream( openmode mode )
stringstream( string s, openmode mode )
ostringstream()
ostringstream( openmode mode )
ostringstream( string s, openmode mode )
istringstream()
istringstream( openmode mode )
istringstream( string s, openmode mode )
The stringstream, ostringstream, and istringstream objects are used for input and output to a string. They behave in a manner similar to fstream, ofstream and ifstream objects. The optional mode parameter defines how the file is to be opened, according to the io_stream_mode_flags. An ostringstream object can be used to write to a string. This is similar to the C sprintf() function. For example:
ostringstream s1;
int i = 22;
s1 "Hello " string s2 = s1.str();
cout
An istringstream object can be used to read from a string. This is similar to the C sscanf() function. For example:
- Dec 20 Sat 2008 13:20
[sstream](存資料)1
C++ String Streams
String streams are similar to the and libraries, except that string streams allow you to perform I/O on strings instead of streams. The library provides functionality similar to sscanf and sprintf in the standard C library.
Three main classes are available in :
-
stringstream - allows input and output
-
istringstream - allows input only
-
ostringstream - allows output only
String streams are actually subclasses of iostreams, so all of the functions available for iostreams are also available for stringstream. See the C++ I/O functions for more information.
In addition, string streams also supply the following functions:
Constructors | create new string streams |
Operators | read from and write to string streams |
rdbuf | get the buffer for a string stream |
str | get or set the stream's string |
- Nov 18 Tue 2008 13:06
傑民的嘉中程式碼
- Nov 15 Sat 2008 14:33
Ansi 字串 與 TCHAR Unicode 之間的轉換
引用自:井民全觀點 (Jing's Perspective)
我寫程式習慣使用 TCHAR 來當作字串的資料型態,
但是有些早期的 C programmer 不習慣使用 通用型態的 TCHAR.
當要合作時, 就會出現問題. 這個問題往往會出現在 呼叫 method 的字串轉換上.
把下面這東西寫下來, 以免每次都還要翻程式找出來.
void UnicodeToAnsi(TCHAR *unicode,char* ansi)
{
int n;
n=WideCharToMultiByte(CP_ACP,0,unicode,-1,ansi,0,NULL,FALSE);
WideCharToMultiByte(CP_ACP,0,unicode,-1,ansi,n,NULL,FALSE);
}
void AnsiToUnicode(char* ansi,TCHAR* unicode)
{
int n;
n=MultiByteToWideChar(CP_ACP,0,ansi,-1,0,0);
MultiByteToWideChar(CP_ACP,0,ansi,-1,unicode,n);
- Nov 15 Sat 2008 14:28
學習C++和程式設計的50個觀點
下面的是學C++時要注意的。絕對經典。!!
2.看《Thinking In C++》,不要看《C++變成死相》;
3.看《The C++ Programming Language》和《Inside The C++ Object Model》,不要因為他們很難而我們自己是初學者所以就不看;
4.不要被VC、BCB、BC、MC、TC等詞彙所迷惑——他們都是集成開發環境,而我們要學的是一門語言;
5.不要放過任何一個看上去很簡單的小編程問題——他們往往並不那麼簡單,或者可以引伸出很多知識點;
6.會用Visual C++,並不說明你會C++;
7.學class並不難,template、STL、generic
programming也不過如此——難的是長期堅持實踐和不遺餘力的博覽群書;
8.如果不是天才的話,想學編程就不要想玩遊戲——你以為你做到了,其實你的C++水平並沒有和你通關的能力一起變高——其實可以時刻記住:學C++是為了編遊戲的;
9.看Visual C++的書,是學不了C++語言的;
10.浮躁的人容易說:XX語言不行了,應該學YY;——是你自己不行了吧!?
11.浮躁的人容易問:我到底該學什麼;——別問,學就對了;
12.浮躁的人容易問:XX有錢途嗎;——建議你去搶銀行;
13.浮躁的人容易說:我要中文版!我英文不行!——不行?學呀!
14.浮躁的人容易問:XX和YY哪個好;——告訴你吧,都好——只要你學就行;
15.浮躁的人分兩種:a)只觀望而不學的人;b)只學而不堅持的人;
16.把時髦的技術掛在嘴邊,還不如把過時的技術記在心裡;
17.C++不僅僅是支持面向對象的程序設計語言;
- Nov 14 Fri 2008 16:05
97年嘉中資訊第五題
一個必有偶數層的河內塔,有a b c三根柱子,假設所有的環原本在a柱上,請將奇數號的環移到b柱上,偶數號的環移到c柱上,大的環不能疊在小的環上,請輸出移動過程和最少步驟。
範例輸入:
4
範例輸出:
ring 1 : a -> b
ring 2 : a -> c
ring 1 : b -> c
ring 3 : a -> b
ring 1 : c -> a
ring 2 : c -> b
ring 1 : a -> b
ring 4 : a -> c
ring 1 : b -> a
ring 2 : b -> c
ring 1 : a -> b
總共需要 11 步
以下是我的程式碼,若要看請反白
#include
using namespace std;
int ia,ib,ic;
string fb(int ia)
{
char ca[15];
string sa="";
int ib=0;
while(ia>0)
{
ca[ib++]=ia%10+'0';
ia/=10;
}
if(ib>0)
for(int i=ib-1;i>-1;i--)sa+=ca[i];
else sa="0";
return sa;
}
int fa(int xa=0,int xb=0,string sa="",int fn=0)
{
if(sa.length())sa+=" -> ";
sa+="("+fb(xb)+","+fb(xa)+")";
if((xa+xb)==ic)
{
cout
return 1;
}
int na,nb;
switch(fn)
{
case 0:
na=ia;
nb=xb;
fn=1;
break;
case 1:
if(xa==ia && xb==ib)return 0;
if(xa>ib-xb)
{
na=xa-ib+xb;
nb=ib;
fn=2;
}
else
{
na=0;
nb=xa+xb;
fn=0;
}
break;
case 2:
na=xa;
nb=0;
fn=1;
break;
}
if(fa(na,nb,sa,fn))return 1;
else return 0;
}
int main()
{
while(cin>>ia>>ib>>ic)
{
bool ba=true;
if(ia+ib
if(ia%2==0 && ib%2==0 && ic%2==1)ba=false;
if(ba)ba=fa();
if(!ba)cout
}
}
- Nov 13 Thu 2008 13:03
97年嘉中資訊第四題
有一個32位元的浮點數,請用10進位表示出來,2進位浮點數的定義為:第一個數字如果是0代表正數,如果是1代表負數,2~9位是2的次方數加上127(為了能表示負數次方),10到32位則是表示原數化成2進位後,以類似科學記號的方式表示時的小數部分。
EX: 01000011110001000111100000000000
第一個0代表這是一個正數
2~9表示指數 10000111 所以135-127=8 代表為2的8次方
10到32位為小數部分10001000111100000000000 等於 0.534912
然後再將0.534912+1=1.534912 再乘以2的8次方
所以答案為 392.938
題目會給你2組測資讀入(t4.txt),請輸出2組測資的答案和相加之後的結果
範例輸入(t4.txt)
01000011110001000111100000000000
10000110101000101011000010000000
範例輸出
字串1 01000011110001000111100000000000 = 392.938
字串2 10000110101000101011000010000000 = -6.1197e-035
392.938
- Nov 12 Wed 2008 15:33
97年嘉中資訊第三題
給你2個桶子A、B和無限供應的水,你可以做3個動作:
(1)把一個桶子裝滿水(2)把一個桶子的水倒光(3)把一個桶子的水倒到另一個桶子中。
把水從一個桶子倒到另一個桶子的動作停止有2個可能的原因:
第一個桶子的水倒光了或第二個桶子的水滿了。例如:A有5公升的水,B有6公升的水且B的容量為8公升,則當把A的水倒到B後,B就滿了(8公升)而A中還剩3公升。
在本問題中,給你Ca,Cb,N。Ca,Cb分別代表A桶子和B桶子的容量,而N是我們要求的目標。若到不出此水量,請輸出"NO"。若可以得到N公升的水(以A加B的水量判定),則請輸出水桶水量歷程紀錄。
範例輸入:
8 5 4
4 2 3
6 9 11
4 5 8
範例輸出:
(0,0) -> (8,0) -> (3,5) -> (3,0) -> (0,3) -> (8,3) -> (6,5) -> (6,0) -> (1,5) -> (1,0) -> (0,1) -> (8,1) -> (4,5) -> (4,0)或
(0,0) -> (0,5) -> (5,0) -> (5,5) -> (8,2) -> (0,2) -> (2,0) -> (2,5) -> (7,0) ->(7,5) -> (8,4) -> (0,4)
NO
NO
(0,0) -> (4,0) -> (0,4) -> (4,4)或
- Nov 11 Tue 2008 17:48
97年嘉中資訊學科第二題
這也還是簡單題
請讀取一個 T2.txt 的檔案,裡面共有20行,請將每一行的16進位改以10進位表示。
執行結果:
十六進位表示法 相對應的十進位表示法
0A 10
AA 170
... ...
他格式沒有強制要求,只要有對齊就行了,他題目只有要求讀檔,結果是要留在視窗上給評審看的喔,不是輸出到檔案。
- Nov 11 Tue 2008 17:36
97年嘉中資訊學科第一題
這一題就是資訊召集教授說的簡單題之一
反正就是簡單就是了
這是憑記憶所打的題目,略有出入請見諒。
有一家店正在進行促銷,只要客人買10個餅乾和2個蛋糕就多送1盒巧克力,請已程式輸出最後應給予的物品數量。
執行結果:
請輸入餅乾個數:12
請輸入巧克力盒數:6
請輸入蛋糕個數:3
12個餅乾,7盒巧克力,3個蛋糕。
這議題應該不需要我多費唇舌了吧,比較討厭的是,在比賽現場時,居然只能用ㄅ半下去慢慢打,他們新注音不知用啥方法鎖掉了,奇怪的做法。
- Nov 05 Wed 2008 17:30
c++ 二進位換八進位 十六進位 發問者: 唉唉唉︿!
/*
http://tw.knowledge.yahoo.com/question/question?qid=1608110403995
程式語言 c++ 二進位換八進位 十六進位
發問者: 唉唉唉︿! ( 實習生 5 級)
設計一程式算出一四位小數的二進位換八進位和十六進位
例如我打一四位小數 0.6587 他會列印出他的八進位和十六進位
然後就結束程式
至於換二進位的方法
0.6587*2="1".3174
0.3174*2="0".6348
0.6348*2=...........以此類推
取 " " 內的數字 由上往下取 0.1010101
八進位就*8 十六進位就*16
請進量簡單點 我怕我看不懂 最好成解釋一下主程式碼
謝謝各位了!!!!
知識加會吃程式碼,所以我把程式碼貼在了部落格
網址 http://www.wretch.cc/blog/taichunmin/12818161
有問題直接在我部落格回覆就行了
- Oct 15 Wed 2008 18:00
C++ String 的 Functions
希望對大家有幫助
Constructors | create strings from arrays of characters and other strings |
Operators | concatenate strings, assign strings, use strings for I/O, compare strings |
append | append characters and strings onto a string |
assign | give a string values from strings of characters and other C++ strings |
at | returns the character at a specific location |
begin | returns an iterator to the beginning of the string |
c_str | returns a non-modifiable standard C character array version of the string |
capacity | returns the number of characters that the string can hold |
clear | removes all characters from the string |
compare | compares two strings |
copy | copies characters from a string into an array |
data | returns a pointer to the first character of a string |
empty | true if the string has no characters |
end | returns an iterator just past the last character of a string |
erase | removes characters from a string |
find | find characters in the string |
find_first_not_of | find first absence of characters |
find_first_of | find first occurrence of characters |
find_last_not_of | find last absence of characters |
find_last_of | find last occurrence of characters |
getline | read data from an I/O stream into a string |
insert | insert characters into a string |
length | returns the length of the string |
max_size | returns the maximum number of characters that the string can hold |
push_back | add a character to the end of the string |
rbegin | returns a reverse_iterator to the end of the string |
rend | returns a reverse_iterator to the beginning of the string |
replace | replace characters in the string |
reserve | sets the minimum capacity of the string |
resize | change the size of the string |
rfind | find the last occurrence of a substring |
size | returns the number of items in the string |
substr | returns a certain substring |
swap | swap the contents of this string with another |
- Oct 14 Tue 2008 10:20
知識+971014-1
1.下列何者是錯誤的常數?試指出其錯誤之所在。
(a)134.45L
(b)10km24 ←有錯,不是變數也不是常數
(c)a2048 ←有錯,這是變數的指定方式
(d)1.3453F
2.試撰寫一程式,利用sizeof關鍵字查詢下列各常數所佔的位元組:
(a)578
(b)784000000
(c)6.78f
(d)718.26
(e)6.42e127
用程式跑出來的結果:
578 4
784000000 4
6.78f 4
718.26 8
6.42e127 8
(後面的數字就是大小)
#include