跳到正文

个人记录

输出题解

LittleChasa约 3 分钟
原文

这是 2025年12月5日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2024年10月5日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1

十分Esay。

提供两种方法:

方法1:

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

C++
#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技术,可以输出多行字符,还可以不需要转义符,代码:

C++
#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;
}