227

ANt_XSYY

xi.xi
Giancarlo
Giancarl0

Learningxiaoli
Agust.
copy_right
Pretharp

ShawnWen
cxhzs
yxc的小迷妹

yangxiufeng
trudbot
W._0
xutianyi

8天前

#### C++ 代码

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
void printT(char ch,int times){
for (int i = 1; i <=times; i++)
{
printf("%c",ch);
}
}
int main(){
int n;cin>>n;
int i;
for (i = 1; i < (n+1)/2; i++){
printT(' ',(n-(2*i-1))/2);
printT('*',(2*i-1));
printT(' ',(n-(2*i-1))/2);
printf("\n");
}

for (i=(n+1)/2; i >= 1; i--){
printT(' ',(n-(2*i-1))/2);
printT('*',(2*i-1));
printT(' ',(n-(2*i-1))/2);
printf("\n");
}
return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
int sx = n / 2, sy = n / 2;
for (int i = 0; i < n ; i ++ ){
for (int j = 0; j < n; j ++ ){
if ( abs(sx - i) + abs(sy - j) <= n / 2 ) cout << "*";
else cout << " ";
}
cout << endl;
}
return 0;
}


8天前

1. 超时
2. prime拼错了....

#### C++ 代码

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
int n;cin>>n;
int x;
bool isprime=false;
for (int i = 0; i < n; i++)
{
isprime=true;
cin>>x;
if(x<=1){
isprime=false;
}else{
for (int j = 2; j <= sqrt(x); j++)
{
if(x%j==0){
isprime=false;
break;
}
}
}
if(isprime)printf("%d is prime\n",x);
else printf("%d is not prime\n",x);
}
return 0;
}


9天前

#### 解法2：优化，C++ 代码

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool Isperfect(int num){
int sum=1;
if(num==1)return false;
else{
for (int i = 2; i <= sqrt(num); i++){
if(num%i==0){
if(num/i==i){
sum+=i;
}else{
sum+=i;sum+=(num/i);
}
}
}
if(sum==num){
return true;
}else {
return false;
}
}
}
int main(){
int n;cin>>n;
int x;
while(n>0){
n--;
cin>>x;
if(Isperfect(x)){
printf("%d is perfect\n",x);
}else {
printf("%d is not perfect\n",x);
}
}
return 0;
}


9天前

#### C++ 代码

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;cin>>n;
int ptr=0,pre=1;
//斐波那契数列 0 1 2 2 3 5
//按规律，在0之前是1，-1
//即-1 1 0 1 1 2 3
int temp;
int i=1;
while(i<=n){
i++;
printf("%d ",ptr);
temp=pre;pre=ptr;ptr=temp+ptr;
}
return 0;
}


11天前

cout<<fixed<<setprecision(2)<<what<<endl;

#### C++ 代码

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;cin>>n;
int sum=0,num_c=0,num_r=0,num_f=0;
int i=0;
char which;
int num_temp;
while(i<n){
scanf("%d %c",&num_temp,&which);
switch (which)
{
case 'C':
num_c+=num_temp;
break;
case 'R':
num_r+=num_temp;
break;
case 'F':
num_f+=num_temp;
break;;
}
sum+=num_temp;
i++;
}
printf("Total: %d animals\n\
Total coneys: %d\n\
Total rats: %d\n\
Total frogs: %d\n\
Percentage of coneys: %.2lf %%\n\
Percentage of rats: %.2lf %%\n\
Percentage of frogs: %.2lf %%\n",
sum,num_c,num_r,num_f,
num_c/((double)sum)*100,num_r/((double)sum)*100,num_f/((double)sum)*100);
return 0;
}


11天前

### 算法1

malloc，但是现在不想学，先码住（下次一定）

### 算法2

#### C++ 代码

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n,m;cin>>n>>m;
for(int i=1;i<=n*m;i++){
if(i%m==0){
printf("PUM\n");
}else{
printf("%d ",i);
}
}
return 0;
}


14天前

#### C++ 代码

#include <iostream>
#include <cstdio>
using namespace std;
void bubble_sort(int * arr,int len){
int t;
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len-i-1; j++)
{
if(*(arr+j)>*(arr+j+1)){
t=*(arr+j);
*(arr+j)=*(arr+j+1);
*(arr+j+1)=t;
}
}
}
}
void CopyArr(int * arr1,int * arr2,int len){
for (int i = 0; i < len; i ++ ){
*(arr1+i)=*(arr2+i);
}
}
int main(){
int a[3];
for (int i = 0; i < 3; i++)
{
cin>>a[i];
}
int b[3];
CopyArr(b,a,3);
bubble_sort(a,3);
for (int i = 0; i < 3; i++)
{
cout<<a[i]<<endl;
}
cout<<endl;
for (int i = 0; i < 3; i++)
{
cout<<b[i]<<endl;
}
return 0;
}


25天前

Orz

#### C++ 代码

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
double sum_d;
cin>>sum_d;
int sum=sum_d*100;
int num[12]={0};
int cash[12]={10000,5000,2000,1000,500,200,100,50,25,10,5,1};
for(int i=0;i<12;i++){
while(sum>=cash[i]){
num[i]++;
sum=sum-cash[i];
}
}
printf("NOTAS:\n");
for(int i=0;i<6;i++){
printf("%d nota(s) de R$%.2lf\n",num[i],cash[i]/100.0); } printf("MOEDAS:\n"); for(int i=6;i<12;i++){ printf("%d moeda(s) de R$ %.2lf\n",num[i],cash[i]/100.0);
}
return 0;
}


1个月前

### 算法1

aver=(权重1)/(总权重)数值1+……+(权重n)/(总权重)数值n

#### C++ 代码

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
float a,b;cin>>a>>b;
double aver=(3.5/(3.5+7.5))*a+(7.5/(3.5+7.5))*b;
cout<<"MEDIA = "<<fixed<<setprecision(5)<<aver;
return 0;
}


1个月前

### 算法1

1.使用C语言的printf("%.4lf",S);
2.使用cout<<fixed<<setprecision(2)<<sum<<endl;
3.使用

    cout.setf(ios::fixed);
cout<<setprecision(3)<<sum<<endl;


4.cout<<setiosflags(ios::fixed)<<setprecision(4)<<sum<<endl;
5.cout<<setprecision(6)<<sum<<endl;

。。。

#### C++ 代码

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double r;cin>>r;
cout<<"A="<< fixed<<setprecision(4)<<(3.14159*r*r);
return 0;
}