You are not allowed to perform this action
cpp:homework:hw2answer
國立屏東大學 資訊工程系 物件導向程式設計
hw1-2 參考解答
using namespace std;
#include <iostream>
int main()
{
string str;
cout << "Please input a name:" ;
getline(cin,str);
if(str.find('-')==-1)
{
int f=str.find(' ')+1;
int l=str.length();
cout << "The initials are " <<str[0] << ". " << str.substr(f,l-f);
cout << " and " << str.substr(f,l-f) << ", " << str[0] << ".\n";
}
else
{
int f=str.find(' ')+1,l=str.length(),d=str.find('-')+1;
cout << "The initials are " <<str[0] << ".-" << str[d]
<< ". " << str.substr(f,l-f);
cout << " and " << str.substr(f,l-f) << ", " << str[d]
<< ".-" << str[0] << ".\n";
}
return 0;
}
cpp/homework/hw2answer.txt · 上一次變更: 2019/07/02 15:01 由 127.0.0.1
