代码仓库
刷算法题的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;
}