用户:
树林归来查看:7 回复:17 评论:7 创建时间:2022-07-14T12:12:24
【社区里谁会C++】
姓梁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=='\r')
{
break;
}
printf("\b ");
gotoxy(2,n);
printf("\b>");
}
gotoxy(0,5);
if(n==2)
{
cout<<"请输入你的加密内容(暂不支持中文):";
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
{
cout<<"请输入你的电码:";
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);
{
for(int j=0;j<10;j++)
{
if(x==b[j])
{
printf("%d",j);
break;
}
}
}
x="";
}
else
{
if(x=="")
{
x=s[i];
}
else
{
x+=s[i];
}
}
}
}
}
操作:选择界面用上下键控制,Enter(回车)确定,然后输入即可
点赞0
评论
Vincent_xiaobo正在学
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, s = 0;
cin >> n;
for(int x = 0; x <= n / 5; x++){
for(int y = 0; y <= n / 2; y++){
int z = n - x * 5 - y * 2;
if(z >= 0) s++;
}
}
cout << s;
return 0;
}点赞0
评论
不知道该叫啥的一只萌新#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int> h[N],c[N];
int dis[N];
void SPFA(int s){
memset(dis,0x3f,sizeof(dis));
dis[s]=0;
queue<int> q;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=0;i<(int)h[x].size();i++){
int u=h[x][i];
if(dis[u]>dis[x]+c[x][i]){
dis[u]=dis[x]+c[x][i];
q.push(u);
}
}
}
}
int main(){
h[0].push_back(1);
c[0].push_back(1);
h[1].push_back(5);
c[1].push_back(2);
h[0].push_back(5);
c[0].push_back(0);
SPFA(0);
printf("%d",dis[5]?"我不会C++!":"我会C++!");
return 0;
}点赞1
评论
#include <iostream>
#include <string>
using namespace std;
struct tWindow{
int top,bottom,left,right;
};
tWindow winA,winB,temp;
tWindow indata(){
cin>>temp.top>>temp.bottom>>temp.left>>temp.right;
return temp;
}
int main(){
winA = indata();
winB = indata();
temp.right = min(winA.right,winB.right);
temp.left = max(winA.left,winB.left);
temp.top = max(winA.top,winB.top);
temp.bottom = min(winA.bottom,winB.bottom);
int s = (temp.right - temp.left) * (temp.bottom - temp.top);
if(temp.right <= temp.left || temp.bottom <= temp.top){
s = 0;
}
cout<<s;
}
【输入】两个窗户的左右上下坐标。
【输出】两个窗户的重合面积,没有则输出0
示范:
10 100 20 60
60 160 50 200
输出:
400(重合面积)
点赞0
评论