猫史档案馆


初学C++

用户:furry烧杯furry烧杯查看:65 回复:10 评论:65 创建时间:2022-05-22T12:45:39


源代码:

#include <iostream>

using namespace std;

int main () {
cout << 7*88 ;
cout << "hello world" ;
return 1;
}


回复

上一页1 页 / 共 1下一页
爱好核平的人爱好核平的人

/*
#include <iostream>

using namespace std;

int main () {
cout << 7*88 ;
cout << "hello world" ;
return 1;
}
*/

【狗头】

点赞0


评论


Esacpe_淸Esacpe_淸

#include<bits/stdc++.h>

using namespace std;

int main()

{

          int a;

          cin>>a; printf(a);

         return 0;

}

点赞0


评论


姓梁monkey淡退姓梁monkey淡退

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<conio.h>
#include<Windows.h>
using namespace std;
string s,x="",a[26]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."},b[10]={"-----",".----","..---","...--","....-",".....","-....","--...","---..","----."};
bool f=false;
char c;
void gotoxy(int xpos, int ypos)
{
	COORD scrn;
	HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
	scrn.X = xpos; scrn.Y = ypos;
	SetConsoleCursorPosition(hOuput, scrn);
}
int main()
{
	int l,xl,q=0,n=2;
	cout<<"摩斯电码程序"<<endl<<"请问你是要加密还是解密:"<<endl<<"  1.加密"<<endl<<"  2.解密"<<endl;
	while(true)
	{
		c=getch();
		if(c=='H' && n>2)
		{
			n--;
		}
		if(c=='P' && n<3)
		{
			n++;
		}
		if(c==' ')
		{
			break;
		}
		printf("\b ");
		gotoxy(2,n);
		printf("\b>");
	}
	gotoxy(0,5);
	if(n==2)
	{
		getline(cin,s);
		l=s.size();
		for(int i=0;i<l;i++)
		{
			if((s[i]<'0' || s[i]>'9') && ((s[i]<'a' ||s[i]>'z') && (s[i]<'A' ||s[i]>'Z')))
			{
				q=0;
				cout<<"/"<<s[i];
			}
			else
			{
				if(q==0)
				{
					q++;
				}
				else
		        {
		        	cout<<"/";
				}
			}
		    if(s[i]>='0' && s[i]<='9')
		    {
		    	xl=b[s[i]-'0'].size();
		    	for(int j=0;j<xl;j++)
		    	{
		    		cout<<b[s[i]-'0'][j];
				}
			}
			if(s[i]>='a' && s[i]<='z')
		    {
		    	xl=a[s[i]-'a'].size();
		    	for(int j=0;j<xl;j++)
		    	{
		    		cout<<a[s[i]-'a'][j];
				}
			}
		}
		cout<<"/";
	}
	else
	{
		getline(cin,s);
		l=s.size();
		for(int i=0;i<l;i++)
		{
			if(s[i]!='.' && s[i]!='-' && s[i]!='/')
			{
				cout<<s[i];
			}
			else if(s[i]=='/')
			{
				for(int j=0;j<26;j++)
				{
					if(x==a[j])
					{
						printf("%c",j+'a');
				        f=true;
				        break;
					}
				}
				if(f);
				{
					x="";
				}
			}
			else
			{
				if(x=="")
				{
					x=s[i];
				}
				else
				{
					x+=s[i];
				}
			}
		}
	}
}

这个是我写的摩斯密码翻译器

给你参考参考【doge】

点赞0


评论


happy_chickenhappy_chicken

#include <iostream>
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;

char Hide() {
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle, &CursorInfo);
	CursorInfo.bVisible = false;
	SetConsoleCursorInfo(handle, &CursorInfo);
	return 0;
}



#define high 20  //定义地图的高度 
#define width 70   //定义地图的宽度 
#define snake_maxlength 100000  //蛇长最大值 
int snake_x[snake_maxlength], snake_y[snake_maxlength]; //蛇的坐标
int snake_length;  //蛇现在的长度
int map[high][width] = {0}; //初始化地图,0表示空格,1表示蛇身,2表示食物。
//3表示墙,4表示蛇头,现在地图中什么也没有
int food_x, food_y; //食物的坐标
int score;  //本局分数
char input;  //读取用户键入的字符
//数据的初始化函数
void setdata() {
	snake_x[0] = high / 2;
	snake_y[0] = width / 3; //初始化蛇头,在地图内的位置随意
	snake_x[1] = high / 2;
	snake_y[1] = width / 3 + 1; //初始化蛇身
	snake_length = 2; //蛇的原始尺寸(一格头一格身子)
	food_x = high / 3, food_y = width / 3; //初始化食物的位置,在地图内位置随意
	score = 0;
	int i, j;
	map[snake_x[0]][snake_y[0]] = 4; //蛇头
	map[snake_x[1]][snake_y[1]] = 1; //蛇身
	map[food_x][food_y] = 2; //食物
	for (i = 0; i < high; i++) //墙
		for (j = 0; j < width; j++)
			if (i == 0 || j == 0 || i == high - 1 || j == width - 1)
				map[i][j] = 3;
}

//画面打印
void gotoxy(int x, int y) { //解释1
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X = x;
	pos.Y = y;
	SetConsoleCursorPosition(handle, pos);
}

void show() {
	gotoxy(0, 0);
	int i, j;
	for (i = 0; i < high; i++) {
		for (j = 0; j < width; j++) {
			HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
			if (map[i][j] == 0)
				cout << " ";
			else if (map[i][j] == 1) {
				SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
				                        FOREGROUND_RED);
				cout << "*";
			} else if (map[i][j] == 2) {
				SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
				                        FOREGROUND_RED |
				                        FOREGROUND_GREEN);
				cout << "@";
			} else if (map[i][j] == 3) {
				SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
				                        FOREGROUND_GREEN |
				                        FOREGROUND_BLUE);
				cout << "#";
			} else if (map[i][j] == 4) {
				SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
				                        FOREGROUND_RED);
				cout << "O";
			}
		}
		printf("\n");
	}
	printf("得分:%d", score);
}

//与输入无关的更新
void updatewithoutinput() {
	int i;
	if (snake_x[0] == food_x && snake_y[0] == food_y) {
		score++;
		srand((unsigned)time(NULL));  //srand和rand函数连用产生随机数,一般以时间作为产生随机数的种子
		food_x = rand() % (high - 3) + 1; //解释2
		food_y = rand() % (width - 3) + 1;
		map[food_x][food_y] = 2;
		snake_length++;
	}
	if (snake_x[0] == 0 || snake_x[0] == high - 1 || snake_y[0] == 0 || snake_y[0] == width - 1) { //碰墙了
		HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
		system("cls");
		SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
		                        FOREGROUND_RED);
		cout << "                                              游戏结束!" << endl;
		getch();
		exit(1);  //解释3
	}
	for (i = 1; i < snake_length; i++) //碰到自己了 ,遍历蛇身找是否和蛇头重复
		if (snake_x[0] == snake_x[i] && snake_y[0] == snake_y[i]) {
			HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
			system("cls");
			SetConsoleTextAttribute(hout, FOREGROUND_INTENSITY |
			                        FOREGROUND_RED);
			cout << "                                               游戏结束!" << endl;
			getch();
			exit(1);
		}
}

void updatewithinput() {
	int i = 1;
	short p = 0;
	if (kbhit()) //解释4
		input = getch();
	if (input == 'w' || input == 'a' || input == 's' || input == 'd') {
		if (p == 1) {
			system("cls");
			p == 0;
		}
		map[snake_x[snake_length - 1]][snake_y[snake_length - 1]] = 0; //蛇走过一格,蛇尾处变为空格
		for (i = snake_length - 1; i > 0; i--) {
			snake_x[i] = snake_x[i - 1]; //走过一格后蛇身的坐标覆盖前面的坐标 (从后往前覆盖,蛇头也会被蛇身覆盖)
			snake_y[i] = snake_y[i - 1]; //解释5
			map[snake_x[i]][snake_y[i]] = 1;
		}

	}
	if (input == 'w')
		snake_x[0]--;
	else if (input == 's')
		snake_x[0]++;
	else if (input == 'a')
		snake_y[0]--;
	else if (input == 'd')
		snake_y[0]++;
	else {
		cout << "     已暂停";
		p = 1;
	}
	map[snake_x[0]][snake_y[0]] = 4; //蛇头的坐标覆盖前面的坐标
}

int main() {
	setdata();//数据初始化
	Hide();//隐藏光标
	while (1) {
		show();  //画面打印
		updatewithoutinput();   //与输入无关的更新
		updatewithinput();      //与输入有关的更新
		Sleep(100);
	}


	return 0;
}

 

点赞0


评论


happy_chickenhappy_chicken

收徒了,C++至少会格式化输入输出即可。

点赞0


评论


happy_chickenhappy_chicken

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
	HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//三色相加,白色
	cout<<"white"<<endl;
	SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|
	FOREGROUND_RED);//红色
    cout<<"red"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_GREEN);//绿色
    cout<<"green"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_BLUE);//蓝色
    cout<<"blue"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);//红色和绿色相加,黄色
    cout<<"yellow"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);//红色和蓝色相加,粉色
    cout<<"pink"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);//绿色和蓝色相加,青色
    cout<<"cyan"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY);//没有添加颜色,原色
    cout<<"grey"<<endl;
    SetConsoleTextAttribute(hout,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//三色相加,白色
    return 0;
}
//这些就是此函数所有颜色,system也行

点赞1


评论


happy_chickenhappy_chicken

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <windows.h>

using namespace std;
char Hide() {
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle, &CursorInfo);
	CursorInfo.bVisible = false;
	SetConsoleCursorInfo(handle, &CursorInfo);
	return 0;
}

void gotoxy(int x, int y) { //定位光标,x为行坐标,y为列坐标
	COORD pos = {x, y}; //(坐标  位置);
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);  //得到标准处理(标准输出处理);
	SetConsoleCursorPosition(hOut, pos);//设置控制台光标位置;
}

void hidden() { //隐藏光标
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cci;
	GetConsoleCursorInfo(hOut, &cci);
	cci.bVisible = 0; //赋1为显示,赋0为隐藏
	SetConsoleCursorInfo(hOut, &cci);
}

class Timer {
	private:
		long start_time;
		long pause_time;
		//两个bool值标记四种状态
		bool is_pause; //记录计时器的状态 (是否处于暂停状态)
		bool is_stop;//是否处于停止状态
	public:
		Timer();
		bool isPause(); //返回计时器状态
		bool isStop();
		//计时器的三种动作(功能)
		void Start();
		void Pause();
		void Stop();
		inline long getStartTime() {
			return start_time;
		}
		void show();
};

Timer::Timer() {
	is_pause = false; //初始化计时器状态
	is_stop = true;
}


bool Timer::isPause() {
	if (is_pause)
		return true;
	else
		return false;
}

bool Timer::isStop() {
	if (is_stop)
		return true;
	return false;
}

void Timer::Start() { //开始
	if (is_stop) {
		start_time = time(0);
		is_stop = false;
	} else if (is_pause) {
		is_pause = false;
		start_time += time(0) - pause_time; //更新开始时间:用此时的时间 - 暂停时所用的时间 + 上一次开始的时间 = 此时的开始时间
	}
}

void Timer::Pause() { //暂停
	if (is_stop || is_pause) //如果处于停止/暂停状态,此动作不做任何处理,直接返回
		return;
	else {  //否则调制为暂停状态
		is_pause = true;
		pause_time = time(0); //获取暂停时间
	}
}

void Timer::Stop() { //停止
	if (is_stop) //如果正处于停止状态(不是暂停状态),不做任何处理
		return ;
	else if (is_pause) { //改变计时器状态
		is_pause = false;
		is_stop = true;
	} else if (!is_stop) {
		is_stop = true;
	}
}

void Timer::show() {
	long t = time(0) - start_time;
	gotoxy(35, 12);
	cout << setw(2) << setfill('0') << t / 60 / 60 << ":"
	     << setw(2) << setfill('0') << t / 60 << ":"
	     << setw(2) << setfill('0') << t % 60 << endl;
}

int main() {
	Hide();
	Timer t;
	char ch;
	hidden();//隐藏光标
	system("color 02");
	gotoxy(35, 12);
	cout << "00:00:00";
	gotoxy(20, 18);
	cout << "按a开始,按空格暂停,按s停止";
	while (1) {
		if (kbhit()) {
			ch = getch();
			switch (ch) {
				case 'a':
					t.Start();
					break;
				case 's':
					t.Stop();
					break;
				case ' ':
					t.Pause();
					break;
				default :
					break;
			}
		}
		if (!t.isStop() && !t.isPause()) {
			t.show();
		}
	}

}
//简单计时器

点赞2


评论


浅唱大弟浅唱大弟

好简单

点赞0


评论


happy_chickenhappy_chicken

#include<cstdio>
#include<windows.h>
using namespace std;
int main()
{
    int a=0;
    while(true){
        Sleep(1000);
        a++;
        printf("%d",a);
    }
    retrun 0;
}//这种计时器,虽然简单,但是只能计秒

点赞0


评论


麟_月麟_月

11

点赞0


评论