跳到正文

Uchiha_Sasuke_7_23

1659525

俺はうちはサスケ

在洛谷打开
资料、奖项与版本

资料

编号
1659525
抓取

源代码:

C++
#include<bits/stdc++.h>
using namespace std;
#define lint long long
signed main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    return 0;
}

最大公因数与最小公倍数:

C++
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int lcm(int a, int b)
{
	return a / gcd(a, b) * b;
}

回文数/字符串判断:

C++
bool is_PalNum(int n)
{
	int m = n, r = 0;
	while (m)
	{
		r = r * 10 + m % 10;
		m /= 10;
	}
	return r == n;
}
bool is_PalStr(string s)
{
	string t = s;
	reverse(t.begin(), t.end());
	return t == s;
}

判断完全平方数:

C++
bool is_Perfect_Square(int n)
{
	int m = sqrt(n);
	return m * m == n;
}

阶乘和:

C++
int factorial(int n)
{
	int f = 1;
	for (int i = 2; i <= n; i++)
		f *= i;
	return f;
}

数字翻转:

C++
int reverse(int n)
{
	int r = 0;
	while (n)
	{
		r = r * 10 + n % 10;
		n /= 10;
	}
	return r;
}

素数判断:

C++
bool is_Prime(int n)
{
	if (n < 2) return false;
	for (int i = 2; i * i <= n; i++)
		if (n % i == 0) return false;
	return true;
}

数位和:

C++
int dig_sum(int n)
{
	int s = 0;
	while (n)
	{
		s += n % 10;
		n /= 10;
	}
	return s;
}

高精度函数:

C++
string add(string x, string y) {
	int a[10005] = {}, b[10005] = {}, c[10005] = {};
	int lenx = x.size(), leny = y.size();
	for (int i = 1;i <= lenx;i++)a[i] = int(x[lenx - i] - '0');
	for (int i = 1;i <= leny;i++)b[i] = int(y[leny - i] - '0');
	int lenans = max(lenx, leny);
	for (int i = 1;i <= lenans;i++)c[i] = a[i] + b[i];
	for (int i = 1;i <= lenans;i++) {
		c[i + 1] += c[i] / 10;
		c[i] %= 10;
	}
	if (c[lenans + 1] != 0)lenans++;
	string ans = {};
	for (int i = lenans;i >= 1;i--) {
		ans = char(c[lenans - i + 1] + '0') + ans;
	}
	return ans;
}//加法

string sub(string x, string y) {
	string ans = {};
	int a[10005] = {}, b[10005] = {}, c[10005] = {};
	int lenx = x.size(), leny = y.size();
	if (y.size() > x.size()||(y.size()==x.size()&&y>x)){
		swap(x, y);
		ans = '-';
	}
	for (int i = 1;i <= lenx;i++)a[i] = int(x[lenx - i] - '0');
	for (int i = 1;i <= leny;i++)b[i] = int(y[leny - i] - '0');
	int lenans = lenx;
	for (int i = 1;i <= lenans;i++)c[i] = a[i] - b[i];
	for (int i = 1;i <= lenans;i++) {
		if (c[i] < 0) {
			c[i] += 10;
			c[i+1]--;
		}
	}
	while (lenans > 1 && c[lenans] == 0)lenans--;
	for (int i = lenans;i >= 1;i--) {
		ans = ans + char(c[i] + '0');
	}
	return ans;
}//减法

string mul(string x, string y) {
	int a[100005] = {}, b[10005] = {}, c[10005] = {};
	string ans = {};
	int lenx = x.size(), leny = y.size();
	for (int i = 1;i <= lenx;i++)a[i] = int(x[lenx - i] - '0');
	for (int i = 1;i <= leny;i++)b[i] = int(y[leny - i] - '0');
	int lenans = lenx + leny - 1;
	for (int i = 1;i <= lenx;i++) {
		for (int j = 1;j <= leny;j++) {
			c[i + j - 1] += a[i] * b[j];
		}
	}
	for (int i = 1;i <= lenans;i++) {
		c[i + 1] += c[i] / 10;
		c[i] %= 10;
	}
	while (c[lenans + 1]) {
		lenans++;
		c[lenans + 1] = c[lenans] / 10;
		c[lenans] %= 10;
	}
	for (int i = lenans;i >= 1;i--) {
		ans = char(c[lenans - i + 1] + '0') + ans;
	}
	return ans;
}//乘法

string div(string x, long long y) {
	struct answer {
		string ans;
		string rem;
	};
	answer ans = {};
	int a[10005] = {};
	int lenx = x.size();
	for (int i = 1;i <= lenx;i++)a[i] = char(x[lenx - i] - '0');
	for (int i = 1;i <= lenx;i++) {
		ans.ans = char((ans.rem * 10 + a[i]) / y + '0');
		ans.rem = (ans.rem * 10 + a[i]) % y;
	}
	int id = 1;
	while (id <= lenx && ans.ans[id - 1] == '0')id++;
	return ans.ans.substr(id);
}//除法(不一定对哦!)

迪杰斯特拉

C++
void dijkstra(int start){
    memset(dist,0x3f,sizeof(dist));
    memset(vis,0,sizeof(vis));
    dist[start]=0;
    for(int i=1;i<=n;i++){
        int mindist=0x3f3f3f3f;
        int minu;
        for(int j=1;j<=n;j++){
            if(vis[j]==0&&dist[j]<mindist){
                mindist=dist[j];
                minu=j;
            }
        }
        for(int j=0;j<g[minu].size();j++){
            int v=g[minu][j].v;
            int w=g[minu][j].w;
            if(dist[minu]+w<dist[v]){
                dist[v]=dist[minu]+w;
            }
        }
        vis[minu]=1;
    }
}

电脑状态检测器:

C++
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
string ans;
int main(){
	srand(time(NULL));
	cout<<"欢迎使用电脑运行状态检测器,准确率为100%,好评率为100%!"<<endl;
	system("pause");
	cout<<"正在检测内存读写"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测硬盘读写"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测CPU温度"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测显卡温度"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测软件程序"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测显示器分辨率"<<endl;
	Sleep(rand()%4000); 
	cout<<"正在检测正在使用人机智能排查"<<endl;
	Sleep(rand()%4000); 
	int n=rand()%8;
	if(n==0)ans="【死机】"; 
	else if(n==2)ans="【关机】"; 
	else if(n==3)ans="【开机】"; 
	else if(n==4)ans="【半开半关】"; 
	else if(n==5)ans="【量子纠缠】"; 
	else if(n==6)ans="【旋转跳跃】"; 
	else ans="【………………………】"; 
	cout<<"您的电脑运行状态是:"<<ans; 
	Sleep(5000); 
    return 0;
}


C++小游戏 c++小游戏2

还没有收录这位用户的文章。