输出题解

· · 个人记录

十分Esay。

提供两种方法:

方法1:

使用反斜杠转义来输出,代码:

#include<bits/stdc++.h>
#define fr(x,y,z,t) for(int x=(y);x<=(z);x+=t)
#define rf(x,y,z,t) for(int x=(y);x>=(z);x+=t)
using namespace std;
main(){
    int t;
    cin>>t;
    if(t==1){
        cout<<"\"How to make the computer print 'Hello world'?\"\n\"You need to input 'printf(\"Hello world\");' into the computer.\"";
    }
    if(t==2){
cout<<
"\\\\    \\\\    \\\\\\\\\\\\\\\\    \\\\        \\\\        \\\\\\\\\\\\\\\\\n"<<
"\\\\    \\\\    \\\\          \\\\        \\\\        \\\\    \\\\\n"<<
"\\\\////\\\\    \\\\\\\\\\\\\\\\    \\\\        \\\\        \\\\    \\\\\n"<<
"\\\\    \\\\    \\\\          \\\\        \\\\        \\\\    \\\\\n"<<
"\\\\    \\\\    \\\\\\\\\\\\\\\\    \\\\\\\\\\\\    \\\\\\\\\\\\    \\\\\\\\\\\\\\\\\n";
    }
    if(t==3){
        cout<<"duiyu\"iostream\",tazhanlewomenshenghuode100%.";
    }
    return 0;
}

方法2:

C++11增加了raw string literal技术,可以输出多行字符,还可以不需要转义符,代码:

#include<bits/stdc++.h>
#define fr(x,y,z,t) for(int x=(y);x<=(z);x+=t)
#define rf(x,y,z,t) for(int x=(y);x>=(z);x+=t)
using namespace std;
main(){
    int t;
    cin>>t;
    if(t==1){
        cout<<R"("How to make the computer print 'Hello world'?"  
"You need to input 'printf("Hello world");' into the computer.")"; 
    }
    if(t==2){
        cout<<R"(\\    \\    \\\\\\\\    \\        \\        \\\\\\\\
\\    \\    \\          \\        \\        \\    \\
\\////\\    \\\\\\\\    \\        \\        \\    \\
\\    \\    \\          \\        \\        \\    \\
\\    \\    \\\\\\\\    \\\\\\    \\\\\\    \\\\\\\\)";
    }
    if(t==3){
        cout<<R"(duiyu"iostream",tazhanlewomenshenghuode100%.)";
    }
    return 0;
}