跳到正文

个人记录

小卖部游戏

jamie999约 11 分钟
原文
文章信息与版本

文章信息

发布
2025年10月8日
收录
2026年9月14日
更新
2026年11月14日
篇幅
约 11 分钟
获赞
1

版本

  1. v1当前
C++
#include <bits/stdc++.h>
#include <fstream>
#include <windows.h>
#define  pii  pair<int,int>
#define next next_permutation
const double pi=3.14159;
#define mp make_pair
#define pq priority_queue
#define ull unsigned long long
const ull base=131;
const ull MOD=1e9+7;
const ull maxn=1000005;
const ull INF=1000000000;
//using namespace std;
bool huiwen(int x){
	string xa=to_string(x);
	string xb=to_string(x);
	reverse(xb.begin(),xb.end());
	if(xb==xa){
		return true;
	}
	return false;
}
long long jiecheng(int x){
    if(x==1){
        return 1;
    }
    return jiecheng(x-1)*x;
}
int yinshuofn(int n){
	int cnt=0;
	for(int i=1;i<=n/2;i++){
		if(n%i==0){
			cnt++;
		    if(n/i!=i){
				cnt++;
			}
		}
	}
	return cnt;
}
bool wuanquanshu(int x){
	int cnt=0;
	for(int i=2;i<x/2;i++){
		if(x%i==0){
			cnt+=i;
			if(x/i!=i){
				cnt+=x/i;
			}
		}
	}
	cnt++;
	if(cnt==x){
		return true;
	}
	else{
		return false;
	}
}
bool runnian(int x){
	if(x%4==0){
		if(x%100==0){
			if(x%400==0){
				return true;
			}
			else{
				return false;
			}
		}
		else{
			return true;
		}
	}
	else{
		return false;
	}
}
bool isodd(int x){
	 if(x%2==0){
	 	return false;
	 }
	 else{
		return true;
	 }
}
bool isprime(int x){
	if(x==1||x<=0){
		return false;
	}
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}
int gcd(int a,int b){
	if(a%b==0){
		return b;
	}
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a*b/gcd(a,b);
}
map<string,int>money;
map<string,int>geshu;
set<string>zhao; 
vector<pair<string,int>>yy; 
//int yinyee=0;
set<string>ss;
double jishuqi=0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ofstream fout("小卖部2.txt");
	ofstream out("卖.txt");
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<"                                              小卖部游戏       加载资源中......" <<endl;
	for(int i=1;i<=66;i++){
		cout<<"■";
		Sleep(111);
	}
	Sleep(11111);
	for(int i=1;i<=33;i++){
		cout<<"■";
		Sleep(111);
	}
	Sleep(15000);
	cout<<"■";
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	printf("请进货\n");
	string s;
	int mm,geg;
	while(1){
		cin>>s;
		if(s=="不进了"){
			break;
		}
		cin>>mm>>geg;
		money[s]=mm;
		geshu[s]+=geg;
		out<<s<<' '<<mm<<"元 "<<geg<<"个"<<endl;
		ss.insert(s);
	}
//	while(jdj!=4){
		bool flag=0;
		Sleep(2000);
		cout << "欢迎光临" << endl;
	    Sleep(1000);
	         cout<< "你需要什么吗?" << endl;
	    for (;;) {
	    	if(flag==1){
	    		break;
			}
	        string buy1;
	        for (int i = 1;; i++) {
	            cin >> buy1;
	            if (buy1 == "不要了") {
	//            	cout<<jishuqi<<endl;
	//                printf("一共%.2f元", jishuqi);
					if(isprime((int)(jishuqi-1))){
						printf("恭喜!由于需支付的钱数是质数+1,所以获得一张优惠50元券,是否使用?\n");
						string tfjcm; 
						cin>>tfjcm;
						if(tfjcm=="是") {
							jishuqi-=50;
							if(jishuqi<0){
								jishuqi=0;
							}
						}
					}
					Sleep(1000);
					cout<<"请输入电话号码以支付..."<<endl;
					string dhh;
					cin>>dhh;
					int cnt=0;
					while(dhh.size()!=11){
						cout<<"电话号码错误!"<<endl;
						cin>>dhh;
						cnt++;
						if(cnt==5){
							cout<<"无效购买,请勿继续。" ; 
						}
					}
					cout<<"到账"<<jishuqi<<"元"<<endl;
//					yinyee+=jishuqi;
	                for (int i = 1; i <= 5; i++){
	                    printf("\n■■■■■■■■■■■■");
	                    Sleep(1000);
					}
					cout<<endl;
					for(auto it=yy.begin();it!=yy.end();it++){
						cout<<it->first<<' '<<it->second<<"个"<<endl;
						fout<<it->first<<' '<<it->second<<"个"<<endl;
					}
					printf("一共%.2f元\n", jishuqi);
	                fout<<fixed<<setprecision(2)<<jishuqi<<endl;
	                fout<<"电话号码:"<<dhh<<endl;
					fout.close();
	                Sleep(1000);
	                for (int i = 1; i <= 5; i++){
	                    printf("■■■■■■■■■■■■\n");
	                    Sleep(1000);
					}
					for(int i=1;i<=50;i++)
					cout <<endl;
					flag=1;
	                break;
	            }
				else{
	            	if(ss.find(buy1)==ss.end()){
	            		cout << "没有该商品。"<<endl;
					}
					else{
						printf("几个?\n");
						int gs;
						cin>>gs;
						if(geshu[buy1]>=gs){
							jishuqi=jishuqi+gs*money[buy1];
							geshu[buy1]-=gs;	
							if(zhao.find(buy1)==zhao.end()){
								yy.push_back({buy1,gs});
								zhao.insert(buy1);
							}
							else{
								for(auto it=yy.begin();it!=yy.end();it++){
									if(it->first==buy1){
										it->second+=gs;
										break;
									}
								}
							}
							out<<endl<<buy1<<' '<<geshu[buy1];
						}
						else{
							if(geshu[buy1]==0){
								cout<<"没货了,下次再进。"<<endl;
							}
							else{
								cout<<"只有"<<geshu[buy1]<<"个货了,是就拿这么多还是下次再来?"<<endl;
								string mai;
								cin>>mai;
								if(mai=="就拿这么多"){
									jishuqi=jishuqi+geshu[buy1]*money[buy1];
									yy.push_back({buy1,geshu[buy1]});
									geshu[buy1]=0;
									out<<endl<<buy1<<' '<<geshu[buy1];
								}
							}
						}
					}
				} 
	            cout << "还要什么吗?" << endl;
	        }
	    }
//	}
//	printf("%.2f",1.0*yinyee/4);
    return 0;
}

游戏

原文
抓取于
  1. jamie999

    太好玩了!