(个人水平有限,请见谅!)
题目描述:
Please create a function to extract the filename extension from the given path,return the extracted filename extension or null if none.
*输入描述:
输入数据为一个文件路径。
输出描述:
对于每个测试实例,要求输出对应的filename extension。
输入:
Abc/file.txt
输出:
txt
代码示例:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int flag = -1;
cin >> str;
for(int i = 0; i < str.size(); i++)
{
if (str[i] == '.')
flag = i+1;
}
(flag != -1) ? (cout << str.substr(flag)) : (cout << "null");
}