ac 但写得就像坨答辩 过两天我自己都忘了这些变量用来干嘛的了
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <math.h> 5 6 int main() 7 { 8 int num[1000]; 9 int i = 0; 10 for (int i = 0, j = 1, k = 1; i < 1000; i++) 11 { 12 num[i] = j; 13 14 j = j + (k * 2 + 1) * 2; 15 k++; 16 } // 此数组存储着能组成沙漏的符号个数 17 int p; 18 char ch; 19 scanf("%d %c", &p, &ch); 20 i = 0; 21 if(p<7){ 22 printf("%c\n",ch); 23 printf("%d",p-1); 24 return 0; 25 } 26 while (p >= num[i]) 27 { 28 i++; 29 } // 按num[i-1]得到沙漏符号数 30 int q = i - 1; 31 int m = q * 2 + 1; 32 int r = 0; 33 int rs = 0; 34 for (int t = 0; t < (num[i - 1] - 1) / 2; t++) 35 { 36 printf("%c", ch); 37 38 if (t + 1 == m) 39 { 40 printf("\n"); 41 r++; 42 rs = r; 43 if (r <= i - 2) 44 { 45 for (; rs > 0; rs--) 46 { 47 printf(" "); 48 } 49 } 50 51 q--; 52 m = m + q * 2 + 1; 53 } 54 } 55 q = i - 2; 56 for (int t = 0; t < i - 1; t++) 57 { 58 printf(" "); 59 } 60 printf("%c\n", ch); 61 m = 3; 62 int ms = 3; 63 r = 0; 64 rs = 0; 65 int j=i-1; 66 for (int t = 0; t < (num[i - 1] - 1) / 2; t++) 67 { 68 if (rs == r) 69 { 70 71 for (int l = j - 1; l > 0; l--) 72 { 73 printf(" "); 74 } 75 j--; 76 rs++; 77 } 78 79 printf("%c", ch); 80 if (t + 1 == m && m != (num[i - 1] - 1) / 2) 81 { 82 rs = r; 83 printf("\n"); 84 m = m + ms * 2 - 1; 85 ms++; 86 } 87 } 88 printf("\n%d", p - num[i - 1]); 89 return 0; 90 }
标签:1027,ch,pat,沙漏,rs,int,++,num,printf From: https://www.cnblogs.com/Npc-Hb/p/17231683.html