每日三百行代码 第二十二天

#include<stdio.h>
int main()
{
   
	int i,j=1,x=0,y=0,rest,N;
	char C;
	scanf("%d %c",&N,&C);
	while(2*j*j-1<=N)//计算层数
	{
   
		j++;
	}
	j--;
	y=2*j-1;	
	rest=N-2*j*j+1;//剩下字符的数量
	while(y>0)//输出沙漏上半部分
	{
   
		for(i=0;i<x;i++)
			printf(" ");
		for(i=0;i<y;i++)
			printf("%c",C);
		printf("\n");
		x++;
		y-=2;
	}
	x--;
	y+=2;
	while(x>0)//输出沙漏下半部分
	{
   
		x--;
		y+=2;
		for(i=0;i<x;i++)
			printf(" ");
		for(i=0;i<y;i++)
			printf("%c",C);
		printf("\n");	
	}
	printf("%d",rest);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   
    int n,i,j,flag,k,sum=0,w=0;
    int a[112345];
    a[0]=2;
    scanf("%d",&n);
    for(i=3; i<=n; i++)
    {
   
        flag=1;
        k=sqrt(i);
        for(j=2; j<=k; j++){
   
            if(i%j==0){
   
                flag=0;
                break;
            }
        }
        if(flag){
   
            a[++w]=i;
        }
    }
    for(i=0; i<=w; i++)
    {
   
        if(a[i+1]-a[i]==2)
        {
   
            sum++;
        }
    }
    printf("%d",sum);
}
#include<bits/stdc++.h>
using namespace std;

bool judge(int n)
{
   
	if(n<=1) return false;
	int sqrtN=sqrt(1.0*n);
	for(int i=2;i<=sqrtN;i++)
	{
   
		if(n%i==0) return false;
	}
	return true;
}
int main()
{
   
	int n,cnt=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
   
		if(judge(i)&&judge(i-2))
			cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

#include <stdio.h>

int main() {
   
	int n, m;
	int i, j;
	int k;
	scanf("%d %d", &n, &m);
	int a[n];
	for (i = 0; i < n; i++) {
   
		scanf("%d", &a[i]);
	}
	for (j = 0; j < m; j++) {
   
		k = a[n - 1];
		for (i = n - 1; i > 0; i--) {
   
			a[i] = a[(i - 1 + n) % n];
		}
		a[0] = k;
	}
	for (i = 0; i < n; i++) {
   
		if (i == n - 1)
			printf("%d", a[i]);
		else
			printf("%d ", a[i]);
	
	}
	printf("\n");
	return 0;
}


翻译:请注意,编号 123456789 是一个 9 位数字,正好由 1 到 9 的数字组成,没有重复。翻倍,我们将获得246913578,这恰好是另一个9位数字,正好由1到9的数字组成,只有在不同的排列中。检查,看看结果,如果我们再次加倍!

现在,你应该检查是否有更多的数字与这个属性。即将给定数字翻倍K数字,你要告诉,如果由此产生的数字只包括数字在原始数字的排列。

输入规范:
每个输入包含一个测试案例。每个案例包含一个不超过 20 位数字的正整数。

输出规格:
对于每个测试案例,如果输入数字翻倍仅包含原始数字中数字的排列,则首先打印在行"是"中,如果没有,则第一次打印为"否"。然后在下一行中,打印双倍的数字。

#include <stdio.h>
#include <string.h>
//大数乘法
#define MAX 30
char num[MAX];
int res[MAX]={
   0};
//这里易错,要11位
char a1[11] = "0000000000";
char a2[11] = "0000000000";


int main() {
   
//方便输入
    scanf("%s", num);
    int len = strlen(num);
    int temp, carry = 0, index;
    for(int j=len-1, m=0; len>=0; --len, --j, ++m) {
   
    //这个分支保证可以最高位可以进位
        if(len==0) {
   
            temp = carry;
        }
        else {
   
            temp = (int)(num[j]-'0')*2 + carry;
        }
        res[m] = temp%10;
        carry = temp/10;
    }
    //去除前导0,得到index
    for(index=MAX-1; index>=0; --index) {
   
        if(res[index]!=0) break;
    }
    //下面两个循环比较,桶~~
    for(int i=0; i<strlen(num); ++i) {
   
        ++a1[(int)(num[i]-'0')];
    }
    for(int i=0; i<=index; ++i) {
   
        ++a2[res[i]];
    }
    //注意考虑0的情况
    if(strcmp(a1,a2)==0 || strcmp(num, "0")==0) 
        printf("Yes\n");
    else
        printf("No\n");

    if(strcmp(num, "0")==0) {
   
        printf("0");
    }
    else {
   
        while(index>=0) {
   
            printf("%d", res[index]);
            --index;
        }   
    }
    return 0;
}

#include<stdio.h>
int main()
{
   
    int ch1[21], ch2[22] = {
    0 };
    char temp;
    int i = 0, num[10] = {
    0 };
    while ((temp = getchar()) != '\n')
    {
   
        ch1[i] = temp - '0';
        i++;
        num[(temp - '0')]++;
    }
    int i2 = 21;
    ch2[i2] = (ch1[i-1] * 2) % 10;
    i2--;
    int j = i - 2;
    for (; j >= 0; j--)
    {
   
        int buf = ch1[j + 1] * 2 / 10 + ch1[j] * 2 % 10;
        ch2[i2] = buf;
        i2--;
    }
    ch2[i2] = ch1[j + 1] * 2 / 10;
    if(ch2[i2]!=0)
    i2--;
    for (int k = 21; k > i2; k--)
    {
   
        num[ch2[k]]--;
    }
    int flag = 0;
    for (int i = 0; i < 10; i++)
    {
   
        if (num[i] != 0)
        {
   
            printf("No\n");
            flag = 1;
            break;
        }
    }
    if(flag==0)
    printf("Yes\n");
    int k = 0;
    while (ch2[k] == 0)
    {
   
        k++;
    }
    for (; k < 22; k++)
    {
   
        printf("%d", ch2[k]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int ht[10]={
   0};
string DoubleS(string str)
{
   
	int temp=0,r,carry=0;
	string result="";
	for(int i=str.size()-1;i>=0;i--)
	{
   
		ht[str[i]-'0']++;
		r=(str[i]-'0')*2+carry;
		carry=r/10;
		ht[r%10]--;
		result+=(r%10+'0');
	}
	if(carry!=0) 
	{
   
		result+=(carry+'0');
		ht[carry]--;
	}
	reverse(result.begin(),result.end());
	return result;
}
int main()
{
   
	string ori,res;
	cin>>ori;
	res=DoubleS(ori);
	bool flag=true;
	for(int i=0;i<res.size()&&flag;i++)
	{
   
		if(ht[i]!=0) flag=false;
	}
	if(flag) cout<<"Yes\n";
	else cout<<"No\n";
	cout<<res<<endl;
	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
   
    char card1[54][4] = {
    "S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13",
    "H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13",
    "C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13",
    "D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13",
    "J1","J2" }, card2[54][4] = {
   };
    int n, shuffle[54];
    scanf("%d\n", &n);
    for (int i = 0; i < 54; i++)
    {
   
        scanf("%d", &shuffle[i]);
    }
    for (int i = 1; i <= n; i++)
    {
   
        if (i % 2 == 1)
        {
   
            for (int j = 0; j < 54; j++)
            {
   
                strcpy(card2[shuffle[j] - 1], card1[j]);
            }
        }
        if (i % 2 == 0)
        {
   
            for (int j = 0; j < 54; j++)
            {
   
                strcpy(card1[shuffle[j] - 1], card2[j]);
            }
        }
    }
    if (n % 2 == 1)
    {
   
        printf("%s", card2[0]);
        for (int i = 1; i < 54; i++)
            printf(" %s", card2[i]);
    }
    else
    {
   
        printf("%s", card1[0]);
        for (int i = 1; i < 54; i++)
            printf(" %s", card1[i]);
    }
    return 0;
}

#include <stdlib.h>
#include <stdio.h>
 
int main(){
   
	int a[55],b[55],c[55];
	int i,j,count,m,n;
	scanf("%d",&count);
	for(i=0;i<54;i++){
   
		a[i] = i+1;
		//printf("%d ",a[i]); //创建1-54的数字列表a,对应54张卡牌 
	}
	//printf("\n");
	
	for(i=0;i<54;i++){
   
		scanf("%d",&b[i]);                 //输入排列顺序,存储在b数组内 
		//printf("%d ",b[i]);
	}
	//printf("\n");
	
	for(i=0;i<54;i++){
   
		b[i] = b[i]-1;                     //顺序数全部减一,方便对应数组中的下标值 
		//printf("%d ",b[i]);
	}
	//printf("\n");
	
	for(j=0;j<count;j++){
   
		for(i=0;i<54;i++){
   
			c[b[i]]=a[i];                    //循环赋值count次,得出洗牌后的卡牌数值 
		} 
		for(i=0;i<54;i++){
   
			a[i] = c[i];
		}
	}
	for(i=0;i<54;i++){
   
		//printf("%d ",c[i]);
		
		m = c[i]/13;
		n = c[i]%13;
		if(n==0){
   
			n=13;
			m--;
		}
		if(m==0){
   
			printf("S%d",n);
		}else if(m==1){
   
			printf("H%d",n);
		}else if(m==2){
   
			printf("C%d",n);
		}else if(m==3){
   
			printf("D%d",n);
		}else if(m==4){
   
			printf("J%d",n);
		}
		if(i != 53){
   
			printf(" ");
		}
		
	}
	
	return 0;
} 
//zc-5
#include <stdio.h>

typedef struct PK{
   
	char c;
	int i;
}P;

int main ( void )
{
   
	int k, i, j;
	P p[54];
	scanf( "%d", &k ); 
	int a[54];
	for( i = 0; i < 54; i++ )
		scanf( "%d", &a[i] );
	for( i = 0; i < 54; i++ ){
   
		if( i < 13 ){
   
			p[i].c = 'S';
			p[i].i = i % 13 + 1;
		}
		else if( i < 26 ){
   
			p[i].c = 'H';
			p[i].i = i % 13 + 1;
		}
		else if( i < 39 ){
   
			p[i].c = 'C';
			p[i].i = i % 13 + 1;
		}
		else if( i < 52 ){
   
			p[i].c = 'D';
			p[i].i = i % 13 + 1;
		}
		else{
   
			p[i].c = 'J';
			p[i].i = i % 13 + 1;
		}
	}

	for( j = 0; j < k; j++ )
	{
   
		P s1[54];
		for( i = 0; i < 54 ; i++ )
			s1[ a[i] - 1 ] = p[i];
		for( i = 0; i < 54; i++ )
			p[i] = s1[i];
	}
	for( i = 0; i < 54; i++ ){
   
		if( i != 53 )
			printf( "%c%d ", p[i].c, p[i].i );
		else
			printf( "%c%d", p[i].c, p[i].i );
	}
	return 0;	
}

#include<bits/stdc++.h>
using namespace std;
char s1[5]={
   'S','H','C','D','J'};
int main(){
   
	int card1[55],n,operate[55],card2[55]={
   0};
	for(int i=1;i<55;i++){
   
		card1[i]=i;
	}
	scanf("%d",&n);
	for(int i=1;i<55;i++){
   
		scanf("%d",&operate[i]);
	}
	for(int i=1;i<=n;i++){
   
		for(int j=1;j<55;j++){
   
			card2[operate[j]]=card1[j];
		}
		for(int k=1;k<55;k++){
   
			card1[k]=card2[k];
		}
	}
	for(int i=1;i<55;i++){
   
		if(i!=1){
   
			printf(" ");
		}
		card2[i]--;
		printf("%c%d",s1[card2[i]/13],card2[i]%13+1);
	}
	return 0;
}