部分A+B (15)
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int A,Da,B,Db;
cin>>A>>Da>>B>>Db;
int m=0,n=0;
while(A)
{
if(A%10==Da)
m++;
A/=10;
}
while(B)
{
if(B%10==Db)
n++;
B/=10;
}
int sum1=0,sum2=0;
int i=0;
for(i=0;i<m;i++)
{
sum1=sum1*10+Da;
}
for(i=0;i<n;i++)
{
sum2=sum2*10+Db;
}
cout<<sum1+sum2;
}
A除以B (20)
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
int b;
cin>>a>>b;
int q,r=0;
int flag=0,sign=0;
int i;
for(i=0;i<a.size();i++)
{
r=r*10+(a[i]-'0');
if(r<b&&sign==1)
{
r=r%b;
cout<<"0";
}
else if(r>b)
{
sign=1;
cout<<r/b;
r%=b;
}
//if(!r)break;
}
if(!sign) cout<<"0";
cout<<" "<<r;
}
锤子剪刀布 (20)
#include <bits/stdc++.h>
using namespace std;
int main()
{
char j;
char y;
int i,n;
int flag=0,sign=0,temp=0;
int C1=0,B1=0,J1=0;
int C2=0,B2=0,J2=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>j>>y;
if((j=='C'&&y=='C')||(j=='J'&&y=='J')||(j=='B'&&y=='B'))
sign++;
else if(j=='C'&&y=='J')
{
flag++;
C1++;
}
else if(j=='B'&&y=='C')
{
flag++;
B1++;
}
else if(j=='J'&&y=='B')
{
flag++;
J1++;
}
else if(j=='J'&&y=='C')
C2++;
else if(j=='C'&&y=='B')
B2++;
else if(j=='B'&&y=='J')
J2++;
}
cout<<flag<<" "<<sign<<" "<<n-flag-sign<<endl;
cout<<n-flag-sign<<" "<<sign<<" "<<flag<<endl;
char jia[105];
jia[J1]='J';
jia[C1]='C';
jia[B1]='B';
//cout<<B1<<" "<<C1<<" "<<J1<<" "<<endl;
for(i=flag;i>=0;i--)
if(jia[i]=='J'||jia[i]=='C'||jia[i]=='B')
{
cout<<jia[i];
break;
}
cout<<" ";
char yi[105];
yi[J2]='J';
yi[C2]='C';
yi[B2]='B';
for(i=flag;i>=0;i--)
if(yi[i]=='J'||yi[i]=='C'||yi[i]=='B')
{
cout<<yi[i];
break;
}
}
数字黑洞 (20)
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int number;
cin>>number;
int n=0,i=0;
while(1)
{
i=0;
n=0;
int a[4]={0};
while(number)
{
a[i]=number%10;
number/=10;
n++;
i++;
}
int sum1=0,sum2=0;
sort(a,a+4,cmp);
for(i=0;i<4;i++)
{
cout<<a[i];
sum1=sum1*10+a[i];
}
cout<<" - ";
sort(a,a+4);
for(i=0;i<4;i++)
{
cout<<a[i];
sum2=sum2*10+a[i];
}
cout<<" = "<<sum1-sum2<<endl;
number=sum1-sum2;
if(sum1-sum2==6174) break;
if(sum1-sum2==0) break;
}
}
月饼
#include <iostream>
#include <algorithm>
using namespace std;
struct moon{
double num;//总量
double sum;//总价
double pri;//单价
}a[1223];
bool cmp(moon x, moon y)
{
return x.pri > y.pri;
}
int main()
{
int N, D, i,j=0;
double Sum2 = 0,Sum = 0;
cin >> N >> D;
for (i = 0; i < N; i++)
cin >> a[i].num;
for (i = 0; i < N; i++)
cin >> a[i].sum;
for (i = 0; i < N; i++)
a[i].pri = a[i].sum / (a[i].num*1.0);
sort(a, a + N, cmp);
for(j=0;j<N;j++)
//while(Sum<=D)
{
Sum += a[j].num;
if (Sum >=D)
{
Sum2 +=( D - (Sum - a[j].num))*a[j].pri;
break;
}
else
Sum2 += a[j].sum;
}
printf("%.2f\n",Sum2);
return 0;
}
个位数统计 (15)
#include <iostream>
#include <string>
using namespace std;
int main()
{
string number;
int a[10]={0};
int i;
cin>>number;
for(i=0;i<number.size();i++)
a[number[i]-'0']++;
for(i=0;i<10;i++)
if(a[i]) cout<<i<<":"<<a[i]<<endl;
return 0;
}
D进制的A+B (20)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int A,B,D;
cin>>A>>B>>D;
int sum=A+B;
int a[1005];
int i=0;
while(sum)
{
a[i]=sum%D;
sum/=D;
i++;
}
for(int j=i-1;j>=0;j--)
cout<<a[j];
}
组个最小数 (20)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num[10];
int i,j;
int n=0;
for(i=0;i<10;i++)
{
cin>>num[i];
n+=num[i];
}
int a[55];
int k=0;
int temp;
for(i=0;i<10;i++)
for(j=0;j<num[i];j++)
{
a[k++]=i;
}
for(i=0;i<=k;i++)
{
if(a[i]!=0)
{
temp=a[0];
a[0]=a[i];
a[i]=temp;
break;
}
}
for(i=0;i<k;i++)
cout<<a[i];
}