//------------------------------------filename---------------------------------// /* 题目描述 Please create a function to extract the filename extension from the given path,return the extracted filename extension or null if none. 输入描述: 输入数据为一个文件路径 输出描述: 对于每个测试实例,要求输出对应的filename extension 示例1 输入 Abc/file.txt 输出 txt */ //只要遇到.就把后面输出就行了,注意.如果为最后一个字符的情况 int f5() { string str; cin >> str; if (str.size() != 0) { auto ptr = find(str.cbegin(), str.cend(), ‘.‘); if (ptr != str.cend()) { ++ptr; for (; ptr != str.cend(); ++ptr) cout << *ptr; cout << endl; } else cout << "null"; } return 0; }
原文:http://www.cnblogs.com/CoderZSL/p/7768005.html