代码仓库

刷算法题的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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值