代码仓库

本文分享了多种算法题的解答思路与代码实现过程,包括数值处理、字符串操作及简单的数学计算等内容,适用于初学者练习及参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刷算法题的AC代码保存在这里,以备日后查询。代码的插入顺序类似于栈。

//2016年5月14日00:01:51
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    stringstream ssm;
    string strA;
    string strAns;
    ll a,b;
    bool isNegative=0;

    cin>>a>>b;

    a+=b;

    a<0?(isNegative=1):(isNegative=0);

    a=abs(a);
    ssm<<a;
    ssm>>strA;

    for(int i=strA.length()-1,j=1; i>0; i--,j++)
    {
        strAns=strA[i]+strAns;
        if(j%3==0)
        {
            strAns=","+strAns;
        }
    }
    strAns=strA[0]+strAns;

    isNegative==1?(cout<<"-"<<strAns):(cout<<strAns);

    return 0;
}
//网上看到的别人的代码http://www.nowcoder.com/profile/899290/codeBookDetail?submissionId=149259
#include <stdio.h>
int main()
{
  int a,b;
  int sum;
  while(scanf("%d%d\n",&a,&b) != EOF){
        sum = a+b;
    if(sum < 0){
    printf("-");
    sum = -sum;
    }
    if(sum>=1000000){
        printf("%d,%03d,%03d\n",sum/1000000, (sum/1000)%1000, sum%1000);
    }
    else if(sum >= 1000){
        printf("%d,%03d\n",sum/1000,sum%1000);
    } else{
        printf("%d\n", sum);
    }
  }
  return 0;
}
#include<iostream>
using namespace std;
int main()
{
    int floor=0;
    int eleFloor=0;
    int arrFloor[99999]={0};
    int top=1; 
    
    while(cin>>floor)
    {
        int f=1;//floor is new
        for(int i=1;i<top;i++)
        {
            if(floor==arrFloor[i])
            {
                f=0;
                break;
            }
        }
        
        if(f==1)
        {
            arrFloor[top++]=floor;
        }
        
        if(elefloor-floor <0)
        {
            -(elefloor-floor)*6+5;
        }
    }
}
#include<iostream>
using namespace std;
int main()
{
    int floor=0;
    int eleFloor=0;
    int sumTime=0;
    int arrOldFloor[99999]={0};
    int top=1; 
    
    while(cin>>floor)
    {
        if(arrOldFloor[floor]==0)
        {
            arrOldFloor[floor]=1;
            
            if(eleFloor-floor <0)
            {
                sumTime+=(-(eleFloor-floor))*6+5;
            }
            
            if(eleFloor-floor >0)
            {
                sumTime+=(eleFloor-floor)*4+5;
            }
        }
        
        
    }
    cout<<sumTime;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string engNum[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    stringstream ssm;
    string strNum,strSum;
    int sum=0;
     
    cin>>strNum;
     
    for(int i=0;i<strNum.length();i++)
    {
        sum+=(strNum[i]-'0');
    }
     
    ssm<<sum;
    ssm>>strSum;
     
    for(int i=0;i<strSum.length()-1;i++)
    {
        cout<<engNum[strSum[i]-'0']<<" ";
    }
    cout<<engNum[strSum[strSum.length()-1]-'0'];
     
     
    return 0;
}

《算法竞赛入门经典——训练指南》代码仓库 例题代码 限于篇幅,书上并没有给出所有例题的代码,这里给出了所有例题的代码,并且改进了书上的一些代码。 第一章 32题 38份代码 第二章 28题 30份代码 第三章 22题 23份代码 第四章 19题 21份代码 第五章 34题 39份代码 第六章 24题 26份代码 共159题 177份代码 为了最大限度保证代码风格的一致性,所有例题代码均由刘汝佳用C++语言编写。 所有代码均通过了UVa/La的测试,但不能保证程序是正确的(比如数据可能不够强),有疑问请致信rujia.liu@gmail.com,或在googlecode中提出: http://code.google.com/p/aoapc-book/ [最新更新] 2013-04-23 增加字符串中例题10(UVa11992 Fast Matrix Operations)的另一个版本的程序,执行效率较低,但更具一般性,可读性也更好 2013-04-22 增加字符串部分“简易搜索引擎”代码,可提交到UVa10679 2013-04-13 修正Treap中优先级比较的bug(原来的代码实际上是在比较指针的大小!),加入纯名次树代码 2013-03-31 修正UVa1549标程的bug,即buf数组不够大。 增加线段树部分“动态范围最小值”的完整代码 2013-03-23 修正UVa10054标程的bug,即没有判断是否每个点的度数均为偶数。UVa数据已经更新 LA3401修正了代码和文字不一致的问题 UVa11270增加了答案缓存 2013-03-21 增加线段树部分中两个经典问题的完整代码:快速序列操作I和快速序列操作II 2013-02-28 补全所有159道例题的代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值