華為機試(移動座標)

2021-10-02 12:02:40 字數 967 閱讀 4434

開發乙個座標計算工具, a表示向左移動,d表示向右移動,w表示向上移動,s表示向下移動。從(0,0)點開始移動,從輸入字串裡面讀取一些座標,並將最終輸入結果輸出到輸出檔案裡面。

輸入:合法座標為a(或者d或者w或者s) + 數字(兩位以內)

座標之間以;分隔。

非法座標點需要進行丟棄。如aa10;  a1a;  $%$;  yad; 等。

下面是乙個簡單的例子 如:

a10;s20;w10;d30;x;a1a;b10a11;;a10;

處理過程:

起點(0,0)

+   a10   =  (-10,0)

+   s20   =  (-10,-20)

+   w10  =  (-10,-10)

+   d30  =  (20,-10)

+   x    =  無效

+   a1a   =  無效

+   b10a11   =  無效

+  乙個空 不影響

+   a10  =  (10,-10)

結果 (10, -10)

一行字串
最終座標,以,分隔
示例1

a10;s20;w10;d30;x;a1a;b10a11;;a10;
10,-10
#include #include #include using namespace std;

vectormy_strtok(string str,string pathern)

return v;

}int getnumber(string str)

return stoi(str);

}int main()

cout<}

return 0;

}

座標移動 華為機試 C C

開發乙個座標計算工具,a表示向左移動,d表示向右移動,w表示向上移動,s表示向下移動。從 0,0 點開始移動,從輸入字串裡面讀取一些座標,並將最終輸入結果輸出到輸出檔案裡面。輸入 合法座標為a 或者d或者w或者s 數字 兩位以內 座標之間以 分隔。非法座標點需要進行丟棄。如aa10 a1a yad ...

華為機試整理

include stdafx.h includeusing namespace std int main int argc,tchar argv cout 2.大數相加 用stl的string比較方便,如下,自己測了幾組資料沒有什麼問題。include stdafx.h include includ...

華為機試 2013

1.字串轉換 問題描述 將輸入的字串 字串僅包含小寫字母 a 到 z 按照如下規則,迴圈轉換後輸出 a b,b c,y z,z a 若輸入的字串連續出現兩個字母相同時,後乙個字母需要連續轉換2次。例如 aa 轉換為 bc,zz 轉換為 ab 當連續相同字母超過兩個時,第三個出現的字母按第一次出現算。...