C++多分支和多个if完成题目

第一题、

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int tmp;
	int b=a/100;
	int s=a/10%10;
	int g=a%10;
	if(s<g)
	{
		tmp=s;
		s=g;
		g=tmp;
	}
	if(b<s)
	{
		tmp=b;
		b=s;
		s=tmp;
	}
	if(s<g)
	{
		tmp=s;
		s=g;
		g=tmp;
	}
	cout<<100*b+10*s+g<<endl;
	system("pause");
	return 0;
} 

 第二题、

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+1==b&&b+1==c)
	{
	    cout<<"TRUE"<<endl;
	}
	else if(a+2==b&&b-1==c)
	{
		cout<<"TRUE"<<endl;
	}
	else if(a-1==b&&b+2==c)
	{
		cout<<"TRUE"<<endl;
	}
	else if(a+1==b&&b-2==c)
	{
		cout<<"TRUE"<<endl;
	}
	else if(a-2==b&&b+1==c)
	{
		cout<<"TRUE"<<endl;
	}
	else if(a-1==b&&b-1==c)
	{
		cout<<"TRUE"<<endl;
	}
	else
	{
		cout<<"FALSE"<<endl;
	}
	system("pause");
	return 0;
} 

 第三题、

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>c&&a+c>b&&b+c>a)
	{
	    if(a*a+b*b>c*c)
	    {
	    	cout<<"ruijiao"<<endl;
	    }
	    if(a*a+b*b==c*c)
	    {
	    	cout<<"zhijiao"<<endl;
	    }
	    if(a*a+b*b<c*c)
	    {
	    	cout<<"dunjiao"<<endl;
	    }
	}
	else
	{
		cout<<"no"<<endl;
	}
	system("pause");
	return 0;
} 


版权声明:本文为Zcy_2010原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。