範例輸入1
want
範例輸出1
first:71
last:276
capture:want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want
範例輸入2
things
範例輸出2
first:265
last:0
capture:things you want to do
範例輸入3
substring
範例輸出3
first:0
last:0
capture:
4. 評分項目:
(1) 符合設計說明輸出正確格式配分 10作者: may 時間: 2024-1-8 23:06
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace CSA01
{
class CSA01
{
const string dreams = "There are moments in life when you miss someone so much that " +
"you just want to pick them from your dreams and hug them for real! Dream what " +
"you want to dream;go where you want to go;be what you want to be,because you have " +
"only one life and one chance to do all the things you want to do";
static void Main(string[] args)
{
string word = Console.ReadLine();
int pos1 = dreams.IndexOf(word);
int pos2 = dreams.LastIndexOf(word);
int length;
string words;
if (pos1 >= 0)
{
if (pos1 < pos2)
{
length = (pos2 + word.Length) - pos1;
}
else
{
pos2 = -1;
length = dreams.Length - pos1;
}
words = dreams.Substring(pos1, length);
}
else
{
words = String.Empty;
}
print(pos1 + 1, pos2 + 1, words);
}
static void print(int pos1, int pos2, string words)
{//pos1=>first,pos2=>last,words=>capture
Console.WriteLine("first:" + pos1);
Console.WriteLine("last:" + pos2);
Console.Write("capture:" + words);
Console.ReadKey();
}
}
}
複製代碼
作者: 李泳霖 時間: 2024-1-17 12:33
using ConsoleApp1;
using System;//程式庫呼叫
using System.Linq.Expressions;
namespace HelloWorld//創建一個程式庫(自己定義)
{
class Program//負責一部分工作的人
{
const string dreams = "There are moments in life when you miss someone so much that " +
"you just want to pick them from your dreams and hug them for real! Dream what " +
"you want to dream;go where you want to go;be what you want to be,because you have " +
"only one life and one chance to do all the things you want to do";