时间限制:1秒 空间限制:32768K

题目描述

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


解题思路

直接把'.'后面的东西输出。如果没有'.'就输出"null"。

#include <iostream>
using namespace std;
int main()
{
bool temp;
string str;
while (cin >> str)
{
temp = false;
for (int i = 0; str[i]; i++)
{
if (str[i] == '.')
temp = true;
else if (temp)
cout << str[i];
}
if (!temp)
cout << "null";
cout << endl;
}
return 0;
}