演算法與程式設計 1

2022-09-09 02:15:09 字數 1449 閱讀 7542

1、編寫乙個程式,將a.txt檔案中的單詞與b.txt檔案中的單詞交替合併到c.txt檔案中,a.txt檔案中的單詞用回車符分隔,b.txt檔案中用回車或空格進行分隔。

package com.test;

import j**a.io.file;

import j**a.io.filenotfoundexception;

import j**a.io.filereader;

import j**a.io.filewriter;

import j**a.io.ioexception;

import j**a.util.arrays;

public class testcopychar

/*** 編寫乙個程式,將a.txt檔案中的單詞與b.txt檔案中的單詞交替合併到c.txt檔案中,a.txt檔案中的單詞用回車符分隔,b.txt檔案中用回車或空格進行分隔。

*/public static void testcopy() catch (filenotfoundexception e)

file file1 = new file("./demo/b.txt");

filereader fr1 = null;

try catch (filenotfoundexception e)

filewriter fw = null;

try catch (ioexception e1)

char buf = new char[(int) file.length()];

char bufb = new char[(int) file1.length()];

int len = 0;

int len1 = 0;

try catch (ioexception e)

string astr = new string(buf,0,len);

string bstr = new string(bufb,0,len1);

system.out.println(astr);

system.out.println(bstr);

system.out.println("***********");

string aarr = astr.split("[\n]");

string barr = bstr.split("[ \n]");

system.out.println(arrays.tostring(aarr));

system.out.println(arrays.tostring(barr));

if (aarr.length > barr.length)

} catch (ioexception e)

}}else

} catch (ioexception e)

}} try catch (ioexception e) }

}

程式設計與演算法 1 變數與型別

一 變數命名 由大小寫字母 下劃線和數字組成,由大小寫字母和下劃線開關,長度不限,比如x1 y mycar等等。不能與c 中的關鍵字和型別同名,比如char const public class auto等待。二 變數與資料型別 定義格式 型別 變數名 初始值 比如 int x 10,y 20 un...

資料結構 演算法與程式設計(1)

這部分不會有很系統的講解,只是列舉一些題目,分享一下我和別人的思路。1.1 陣列的查詢 陣列,可以說是最簡單的資料型別,它占用一塊連續的記憶體並按照順序儲存資料。與vector不同,建立陣列時,需要指定陣列的大小,而且不允許動態增加陣列元素。陣列中的記憶體是連續的,而且可以根據下標讀寫元素,時間效率...

part1 演算法分析與程式設計基礎

1.演算法特徵 輸入性 0個或多個輸入 輸出性 1個或多個輸出 確定性 任何條件下,演算法只有唯一執行路徑 有窮性 可行性 2.判斷乙個演算法好壞的標準 正確性 可讀性 健壯性 效率 3 演算法描述 自然語言 框圖 偽 程式語言 程式 資料結構 演算法 4.c 程式檔案分為4個部分 預處理指令 全域...