猫史档案馆


【代码看看】c++、python代码!

用户:Ryan袁奥Ryan袁奥查看:5 回复:7 评论:5 创建时间:2018-12-16T17:25:42


#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
	int x,y,symbol, ans;
	int n, temp,sum=0;
	srand(time(0));
	for(int i=1; i<=15; i++)
	{
		x=rand()%9+1;
		y=rand()%9+1;
		symbol=rand()%2;
		if(x<y&&symbol==1)
		{
			temp=x;
			x=y;
			y=temp;
		
		}
		switch(symbol)
		{
			case 0:
			    ans=x+y;
			    cout<<x<<'+'<<y<<'=';
			    break;
			case 1:
			    ans=x-y;
			    cout<<x<<'-'<<y<<'=';
			    break;
		}
		cin>>n;
		if(n==ans)
		{
			sum+=10;
			cout<<" 对! "<<endl;
		}
		else
		    cout<<"  错!  "<<endl;	
	}
	cout<<"得分"<<sum<<endl;
	return 0;
}

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{                                                                                                                                                                              
int n,a;
cout<<"抽奖程序"<<endl; 
cout<<"请输入1~5中的任一整数:"<<endl;
cin>>n;                                                                                                                                                                    
srand(time(0));
a=rand()%5+1;
if(n==a)cout <<"恭喜您,中奖了!奖金10元。"<<endl;
else cout <<"没中奖,请付费2元。"<<endl;
cout <<"中奖号码是"<<a<<endl;                                                                                                                                             
return 0;
} 
#encoding: utf-8

# requests:一个非常方便的去做网络请求的库.
# pip install requests

import requests
import time
import random
import hashlib

url = "http://fanyi.youdao.com/translate_o?喵artresult=dict&喵artresult=rule"

word = input("请输入要翻译的文字:")
salt = str(int(time.time()*1000) + random.randint(1,9))
# word = "hello"
raw_str = "fanyideskweb" + word + salt + "sr_3(QOHT)L2dx#uuGR@r"
sign = hashlib.md5(raw_str.encode("utf-8")).hexdigest()

data = {
    "i": word,
    "from": "AUTO",
    "to": "AUTO",
    "喵artresult": "dict",
    "client": "fanyideskweb",
    "doctype": "json",
    "version": "2.1",
    "keyfrom": "fanyi.web",
    "action": "FY_BY_REALTIME",
    "typoResult": "false",
    "salt": salt,
    "sign": sign
}
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win喵; x喵) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/69.0.3497.92 Safari/537.36",
    "Host": "fanyi.youdao.com",
    "Origin":"http://fanyi.youdao.com",
    "Referer": "http://fanyi.youdao.com/",
    "Cookie": "OUTFOX_SEARCH_USER_ID=1992865268@182.87.173.10; OUTFOX_SEARCH_USER_ID_NCOO=2134926802.2224576; _ga=GA1.2.359522511.1518241590; P_INFO=18570631587|1540190771|2|study|00&99|CN&1540177284&study#US&null#10#0#0|&0|null|18570631587; _ntes_nnid=448b22d901e81b2cabd喵9e507632f40,1541835430513; youdao_usr_info=dWlkPTg1NTkyOTExNTQ0N喵0NzQ1NzA6c2NudD0xOmZ2dD0xNTQxODQ2MzYyNzI2OmZscD1odHRw_JTNBJTJGJTJGemh1c2hvdS5odWlodWkuY24lMkZpbnN0YWxsZWQlM0Zicm93c2VyJTNEY2hyb21l_JTI2dmVyc2lvbiUzRDQuMy45LjQlMjZ2ZW5kb3IlM0RjaHJvbWVuZXc=; JSESSIONID=aaaShwrrco9q18nvRR9Bw; fanyi-ad-id=52077; fanyi-ad-closed=1; ___rl__test__cookies=1541854572150"
}
response = requests.post(url,data=data,headers=headers)
result = response.json()
tgt = result['translateResult'][0][0]['tgt']
print(tgt)
#include <iostream>
using namespace std;
int sushu(int x)
{
	if(x<=1) return 0;
	if(x==2) return 1;
	for(int i=2;i<=x-1;i++)
		if(x%i==0) return 0;
	return 1;
}
int main()
{
	int i,j,n;
	cout<<"n=";
	do
	{
		cin>>n;
	}while(n<4);
	for(i=4;i<=n;i+=2)
	{
		for(j=2;j<i;j++)
			if(sushu(j))
				if(sushu(i-j))
				{
					cout<<i<<'='<<j<<'+'<<i-j<<endl;
					break;
				}
		if(i==j)cout<<i<<"验证失败!<<endl;		
	}
	return 0;
}
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
	int i,a[4],ans;
	string t[4];
	t[0]="1,2,3,4,5,6,7";
	t[1]="1,3,5,7";
	t[2]="2,3,6,7";
	t[3]="4,5,6,7";
	cout<<"读心术猜数"<<endl;
	cout<<"请你从下面7个数中,选一个并记在心里。"<<endl;
	cout<<t[0]<<endl;
	system("pause");
	for(i=1;i<=3;i++)
	{
	    system("cls");
		cout<<i<<"问:下面的数中有吗?0:没有,1:喵<<endl;
		cout<<t[i]<<endl;
		do
		{
			cin>>a[i];
		}while(a[i]<0||a[i]>1);	
	}
	ans=4*a[3]+2*a[2]+a[1];
	system("cls");
	cout<<"你心中想的数是:";
	cout<<ans<<endl;
	return 0; 	
}


回复

上一页1 页 / 共 1下一页
yamolyamol

代码说的啥呢?光代码是不行的哦,还是有说明会好一些吧。。。。

点赞0


评论


热情的大黄鸡984热情的大黄鸡984

第二个代码在《小学生C++趣味编程》上册里有。

点赞0


评论


HaylaeSTUDIOSHaylaeSTUDIOS

我一直想:C++怎么运行啊!!!!!!!!!!!

点赞0


评论


Python-happyyyyPython-happyyyy

哈哈哈哈

点赞0


评论


庄nnnn额庄nnnn额

喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵

点赞0


评论


umbrallawwumbrallaww

az。。。

点赞0


评论


浮躁的飓风雀HYKa浮躁的飓风雀HYKa

url = "喵喵喵?artresult=dict&artresult=rule"

点赞0


评论