zoukankan      html  css  js  c++  java
  • 每日算法

    每日算法

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.2.23


    记录下来自己做题时得思路,并不一定是最优解

    pat甲-1023 Have Fun with Numbers (hash,字符串,高精度)

    卡了计算出来为0的数据 大家写的时候要小心

    #include <iostream>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    int book[13];
    // 高精度乘法 / 加法 
    string add(string a,string b)
    {
    	string ans;
    	int len = a.size() - 1,j = 0;
    	for(int i = len; i >= 0; i--)
    	{
    		int sum = a[i] - '0' + b[i] - '0' + j;
    		j = 0;
    		while(sum - 10 >= 0){
    			j++;sum-=10;
    		}
    		ans += to_string(sum);
    	}
    	if(j > 0)ans += to_string(j);
    	reverse(ans.begin(),ans.end());
    	return ans;
    }
    int main()
    {
    	string a;
    	cin >> a;
    	for(int i = 0;i < a.size() ;i ++)book[a[i] - '0']++;
    	
    	string ans = add(a,a);
    	
    	for(int i = 0;i < ans.size();i++)book[ans[i] - '0']--;
    	
    	// 卡了计算出来某个位置为0的数字 
    	for(int i = 0;i <= 9 ; i++)
    	{	
    		if(book[i] != 0)
    		{
    			cout << "No" << endl << ans; 
    			return 0;
    		}
    	}	
    	cout << "Yes" << endl << ans << endl;
    	return 0;
    }
    

    pat甲-1024 Palindromic Number (高精度,字符串,回文数)

    #include <iostream>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    string n;
    int  k;
    bool check(string s)
    {
    	for(int i = 0,j = s.size() - 1;j >= 0;i++,j--)
    	{
    		if(s[i] != s[j])return false;
    	}
    	return true;
    }
    
    string add(string a,string b)
    {
    	string ans;
    	int j = 0;
    	for(int i = a.size() - 1;i >= 0; i--)
    	{
    		int sum = a[i] - '0' + b[i] - '0' + j;
    		j = 0;while(sum - 10 >= 0){
    			j++;sum-=10;
    		}
    		ans += to_string(sum);
    	}
    	if(j > 0)ans += to_string(j);
    	reverse(ans.begin(),ans.end());
    	return ans;
    }
    
    void dfs(string x,int step)
    {
    	if(step == k && !check(x))
    	{
    		cout << x << endl << k;
    		return;
    	}
    	if(check(x))
    	{
    		cout << x << endl << step;
    		return;
    	}else {
    		string t = x;
    		reverse(t.begin(),t.end());
    		string sum = add(x,t);
    		dfs(sum,step+1);
    	}
    	
    }
    int main()
    {
    	cin >> n >> k;
    	dfs(n,0);
    	return 0;
    }
    
  • 相关阅读:
    MongoDB Query 的几个方法
    jQuery日期和时间插件(jqueryuitimepickeraddon.js)中文破解版使用
    entity framework使用技巧
    SQL Server TSQL高级查询
    Visual Studio 2012资源管理器里单击打开改为双击打开文件
    ASP.NET MVC 3发布报错(ASP.NET MVC 3在没有安装环境的服务器上运行)的解决方案
    排序算法时间测试比较
    读书笔记之:C++ STL 开发技术导引3
    如何判断整数x的二进制中含有多少个1
    面试题:2012民生银行总行笔试题
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12348826.html
Copyright © 2011-2022 走看看