- 最後登錄
- 2024-9-20
- 在線時間
- 244 小時
- 註冊時間
- 2008-3-25
- 閱讀權限
- 50
- 精華
- 0
- UID
- 3819761
- 帖子
- 487
- 積分
- 11596 點
- 潛水值
- 28699 米
| 本來不想要把全部code都貼上來的, 所以隨便寫寫, 想不到會有那麼多錯誤...
這個是一半的code, 全部的時在太長了><
我是想建立一個int main(), ()裡面不可有東西...
- #include <iostream>
- #include <string>
- using namespace std;
-
- bool isDanceWellFormed(string dance)
- {
- char space = ' ';
- if (dance.at(0) == space)
- return true;
- if (dance.size() > 2)
- {
- for (int i=0; i < dance.size() - 2; i++)
- {
- if (isdigit(i) && isdigit(i+1) && isdigit(i+2))
- {
- cout << "1" << endl;
- return false;
- }
- }
- }
- for (int i=0; i < dance.size(); i++)
- {
- if (dance.at(i) != 'l' && dance.at(i)!= 'L' && dance.at(i)!= 'd'
- && dance.at(i) != 'D' && dance.at(i) != 'r' && dance.at(i) != 'R'
- && dance.at(i) != 'u' && dance.at(i) != 'U' && dance.at(i) != '/' && isdigit(dance.at(i)) == false )
- {
- return false;
- }
- }
-
- for (int i=0; i < dance.size()-1; i++)
- {
- if (isalpha(dance.at(i)) && isalpha(dance.at(i+1)))
- {
- return false;
- }
- else if (isalpha(dance.at(i)) && isdigit (dance.at(i+1))) //checking if letter before digit.
- {
- return false;
- }
- else if (isdigit(dance.at(i)) && dance.at(i+1) == '/') //is (i+1) part right?
- {
- return false;
- }
-
- }
- return true;
- }
- int main()
- {
- for(;;)
- {
- system("cls");
- string dancing;
- cout << "enter dance: ";
- cin >> dancing;
- if (isDanceWellFormed(dancing) == true)
- cout << "wellFormed" << endl;
- else
- cout << "not wellformed" << endl;
- system("pause");
- }
- }
複製代碼 ... |
|