史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   有人可以解答這個程式嗎?? (http://forum.slime.com.tw/thread188757.html)

smalldough 2006-10-13 06:56 PM

有人可以解答這個程式嗎??
 
@@可以的話,能不能用C或C++寫。謝謝。
請撰寫一程式,將文字加密。其加密規則如下:
(1)將字串s 中的奇數位字母先抓出來連在一起,得到s1,其中空白以'*'代替。
(2)再將字串s 中的偶數位字母抓出來連在一起,得到s2,其中空白以'*'代替。
(3)s1, s2 合起來,得到s3。即為密文。
例如:
s = "This is a nice Day.";
s1 就為"Ti*sanc*a."
s2 就為"his**ieDy"
s3 為密文,為"Ti*sanc*a.his**ieDy"
【輸入】:原文
【輸出】:密文
【範例輸入】:SUNNY DAY
【範例輸出】:SNYDYUN*A

ooCatoo 2006-10-14 02:18 AM

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
char inputStr[100];
char ch;
String s1 = "";
String s2 = "";

printf("input string (length < 100) : ");
gets(inputStr);

for (int i = 0; i < strlen(inputStr); i++) {
ch = inputStr[i];
if (ch == ' ') ch = '*';

if (i % 2 == 0) s1 += ch;
else s2 += ch;
}

printf("output : %s", s1 + s2);
}


參考看看囉!

smalldough 2006-10-14 08:41 AM

這位大大再次麻煩你喔~因為之前我COMPILE出現七個錯誤,所以我改錯之後COMPILE這個程式 ,最後出現兩個警告一個錯誤 :最後一個錯誤我看不懂,@@"謝謝你喔
修改錯誤後的程式碼:
#include <stdio.h>
#include <string.h>
void main(){int argc; char*argv[100];}
{
char inputStr[100];
char string;
char ch;
String s1 = "";
String s2 = "";
printf("input string (length < 100) : ");
gets(inputStr);
for (int i = 0; i < strlen(inputStr); i++) {
ch = inputStr[i];
if (ch == ' ') ch = '*';
if (i % 2 == 0) s1 += ch;
else s2 += ch;
}
printf("output : %s", s1 + s2);
}
錯誤訊息:
C:\Documents and Settings\dodo\桌面\123.cpp(3) : warning C4101: 'argc' : unreferenced local variable
C:\Documents and Settings\dodo\桌面\123.cpp(3) : warning C4101: 'argv' : unreferenced local variable
C:\Documents and Settings\dodo\桌面\123.cpp(4) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
123.obj - 1 error(s), 2 warning(s)

ooCatoo 2006-10-14 09:49 AM

1. 原本的七個錯誤是什麼?

2. void main(){int argc; char*argv[100];}
這樣寫不對吧!


所有時間均為台北時間。現在的時間是 05:08 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1