题解 P7869 【「Wdoi-4」使用三个系统程度的能力】

· · 题解

题解

容易发现,本题就是去寻找输入的字符串里是否含有 \verb!\r!\verb!\n!。因为本题保证了文本文件仅在一种系统中产生,因此若仅有前者,则为 \text{Mac} 系统;仅有后者,则为 \text{Linux} 系统;如果都有,则为 \text{Windows} 系统。

参考代码

#include<iostream>
#include<string>
std::string s;
int main(){
    std::getline(std::cin,s); bool f1=0,f2=0;
    if(s.find("\\r")<s.length()) f1=true;
    if(s.find("\\n")<s.length()) f2=true;
    if(f1&&f2) std::cout<<"windows"<<std::endl; else 
    if(f2    ) std::cout<<"linux"<<std::endl; else 
    if(f1    ) std::cout<<"mac"  <<std::endl;
    return 0;
}