zoukankan      html  css  js  c++  java
  • HD-ACM算法专攻系列(2)——Rightmost Digit

    题目描述:

    源码:

    /**/
    #include"iostream"
    using namespace std;
    
    int main()
    {
    	int t, mod;
    	long long n;
    	cin>>t;
    	for(int i = 0; i < t; i++)
    	{
    		cin>>n;
    		mod = n % 10;
    		if(mod == 0 || mod == 1 || mod == 5 || mod == 6)
    		{
    			cout<<mod<<endl;
    		}
    		else
    		{
    			switch(mod)
    			{
    				case 2:
    					mod = n % 4;
    					if(mod == 0)
    					{
    						cout<<6<<endl;
    					}
    					else if(mod == 1)
    					{
    						cout<<2<<endl;
    					}
    					else if(mod == 2)
    					{
    						cout<<4<<endl;
    					}
    					else
    					{
    						cout<<8<<endl;
    					}
    					break;
    				case 3:
    					mod = n % 4;
    					if(mod == 0)
    					{
    						cout<<1<<endl;
    					}
    					else if(mod == 1)
    					{
    						cout<<3<<endl;
    					}
    					else if(mod == 2)
    					{
    						cout<<9<<endl;
    					}
    					else
    					{
    						cout<<7<<endl;
    					}
    					break;
    				case 4:
    					if(n % 2 == 1)
    					{
    						cout<<4<<endl;
    					}
    					else
    					{
    						cout<<6<<endl;
    					}
    					break;
    				case 7:
    					mod = n % 4;
    					if(mod == 0)
    					{
    						cout<<1<<endl;
    					}
    					else if(mod == 1)
    					{
    						cout<<7<<endl;
    					}
    					else if(mod == 2)
    					{
    						cout<<9<<endl;
    					}
    					else
    					{
    						cout<<3<<endl;
    					}
    					break;
    				case 8:
    					mod = n % 4;
    					if(mod == 0)
    					{
    						cout<<6<<endl;
    					}
    					else if(mod == 1)
    					{
    						cout<<8<<endl;
    					}
    					else if(mod == 2)
    					{
    						cout<<4<<endl;
    					}
    					else
    					{
    						cout<<2<<endl;
    					}
    					break;
    				case 9:
    					if(n % 2 == 1)
    					{
    						cout<<9<<endl;
    					}
    					else
    					{
    						cout<<1<<endl;
    					}
    					break;
    			}
    		}
    	}
        return 0;
    }
    

      

  • 相关阅读:
    spring 事务
    spring jdbc学习1
    css学习2
    css学习1
    spring aop 学习1
    spring学习1
    jQuery学习笔记1
    JavaScript学习笔记1
    springboot+quartz+vue+socket实现的定时任务加任务日志实时查看
    hadoop hbase数据备份异常
  • 原文地址:https://www.cnblogs.com/forcheng/p/7634855.html
Copyright © 2011-2022 走看看