卡在出线概率了。40%,没想到遍历时反了,我去。
1.时钟加法
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 11 void Print(int x) { 12 13 14 if (x < 10) { 15 printf("0%d", x); 16 } 17 else { 18 printf("%d", x); 19 } 20 21 22 } 23 24 int main() 25 { 26 int a; 27 int b; 28 int c; 29 int n; 30 while (scanf("%d:%d:%d+%d", &a,&b,&c,&n) != EOF) { 31 32 33 int t = a * 3600 + b * 60 + c * 1 + n; 34 //printf("t=%d\n", t); 35 if (t == 86400) { 36 printf("00:00:00\n"); 37 } 38 else { 39 40 41 42 int r1 = t / 3600; 43 r1 %= 24; 44 int m2 = t % 3600; 45 46 int r2 = m2 / 60; 47 48 int m3 = m2 % 60; 49 50 int r3 = m3; 51 52 Print(r1); 53 printf(":"); 54 55 Print(r2); 56 printf(":"); 57 58 Print(r3); 59 printf("\n"); 60 61 62 } 63 64 65 66 } 67 68 return 0; 69 }
2.卡牌排序
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 int e[10005]; 11 int o[10005]; 12 int main() 13 { 14 int a; 15 while (scanf("%d", &a) != EOF) { 16 memset(e, 0, sizeof(e)); 17 memset(o, 0, sizeof(o)); 18 int num; 19 20 int b = a; 21 int cnt1 = 0, cnt2 = 0; 22 for (int i = 0; i < b; ++i) { 23 24 scanf("%d", &num); 25 26 if (num % 2 == 1) { 27 28 o[cnt1] = num; 29 cnt1++; 30 } 31 else { 32 33 e[cnt2] = num; 34 cnt2++; 35 } 36 37 38 39 } 40 41 //sort 42 for (int j = 0; j < cnt1 - 1; ++j) { 43 for (int i = 0; i < cnt1 - 1 - j; ++i) { 44 45 if (o[i] > o[i + 1]) { 46 int t = o[i]; 47 o[i] = o[i + 1]; 48 o[i + 1] = t; 49 } 50 51 } 52 } 53 54 55 for (int j = 0; j < cnt2- 1; ++j) { 56 for (int i = 0; i < cnt2 - 1 - j; ++i) { 57 58 if (e[i] > e[i + 1]) { 59 int t = e[i]; 60 e[i] = e[i + 1]; 61 e[i + 1] = t; 62 } 63 64 } 65 } 66 67 68 for (int i = 0; i < cnt1; ++i) { 69 printf("%d ", o[i]); 70 } 71 printf("\n"); 72 73 for (int i = 0; i < cnt2; ++i) { 74 printf("%d ", e[i]); 75 } 76 77 printf("\n\n"); 78 79 80 } 81 82 return 0; 83 }
3.小南找书
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 int main() 11 { 12 int n; 13 14 while (scanf("%d", &n) != EOF) { 15 int arr[1005][2] = {0}; 16 //memset(arr[0][0], 0, sizeof(arr)); 17 18 int ai; 19 int sum = 0; 20 int pre = 0; 21 22 for (int i = 1; i <= n; ++i) { 23 scanf("%d", &ai); 24 25 sum += ai; 26 27 if (pre == 0) { 28 arr[i][0] = 0; 29 30 arr[i][1] = sum; 31 32 } 33 else { 34 arr[i][0] = pre + 1; 35 36 arr[i][1] = sum; 37 38 } 39 pre = arr[i][1]; 40 41 } 42 43 44 45 int m; 46 scanf("%d", &m); 47 48 int mb; 49 50 for (int i = 1; i <= m; ++i) { 51 52 //query 53 scanf("%d",& mb); 54 55 56 for (int i = 1; i <= n; ++i) { 57 58 if (arr[i][0] <= mb && arr[i][1] >= mb) { 59 printf("%d\n", i); 60 break; 61 } 62 63 64 } 65 66 67 } 68 69 70 // Print 71 /* for (int i = 1; i <= n; ++i) { 72 printf("%d %d\n", arr[i][0], arr[i][1]); 73 }*/ 74 75 76 } 77 78 return 0; 79 }
4.出线概率
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 #define long long ll 11 12 13 14 void Print(int x) { 15 16 17 if (x < 10) { 18 printf("0%d", x); 19 } 20 else { 21 printf("%d", x); 22 } 23 24 25 } 26 char s[10005]; 27 int main() 28 { 29 30 while (scanf("%s", &s) != EOF) { 31 32 33 int len = strlen(s); 34 35 //printf("%d", len); 36 37 if (len % 2 == 1) { 38 printf("-"); 39 } 40 41 printf("0."); 42 43 if (len % 2 == 1) { 44 45 /*for (int i = 0; i <= len - 2; i +=2) { 46 47 char c2 = s[i] - 'a' + 1; 48 char c1= s[i + 1] - 'a' + 1; 49 50 int n = c1 * 10 - c2; 51 52 Print(n); 53 54 }*/ 55 56 for (int i = len -1 ; i >= 1; i -= 2) { 57 58 char c1 = s[i] - 'a' + 1; 59 char c2 = s[i - 1] - 'a' + 1; 60 61 int n = c1 * 10 - c2; 62 63 Print(n); 64 65 } 66 67 68 printf("%d\n", s[0] - 'a' + 1); 69 70 71 //printf("%d", s[0] - 'a' + 1); 72 73 } 74 else if (len % 2 == 0) { 75 76 77 78 for (int i = len - 1; i >= 0 ; i -= 2) { 79 80 char c1 = s[i] - 'a' + 1; 81 char c2 = s[i - 1] - 'a' + 1; 82 83 int n = c1 * 10 - c2; 84 85 Print(n); 86 87 } 88 printf("\n"); 89 90 //printf("%d\n", s[len - 1] - 'a' + 1); 91 92 93 94 95 } 96 97 98 } 99 100 return 0; 101 }
5.地铁出行
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 int main() 11 { 12 int n; 13 while (scanf("%d", &n) != EOF) { 14 15 int A =100; 16 int B = 0; 17 18 float sum = 0; 19 20 21 22 float price = 0 ; 23 24 for (int i = 0; i < n; ++i) { 25 26 scanf("%f", &price); 27 // printf("price=%f\n", price); 28 if (sum < 10) { 29 price = price; 30 } 31 else if (sum >= 10 && sum < 15) { 32 price = 0.8 * price; 33 } 34 else if (sum >= 15 && sum < 40) { 35 price = 0.5 * price; 36 } 37 else if (sum >= 40) { 38 price = price; 39 } 40 41 sum += price; 42 43 44 //printf("sum=%f\n", sum); 45 46 47 } 48 49 if (A <= sum) { 50 printf("Yes\n"); 51 } 52 else { 53 printf("No\n"); 54 } 55 56 57 58 59 } 60 61 return 0; 62 }
6.填数游戏
1 #include<stdio.h> 2 3 #include<string.h> 4 5 #include<stdlib.h> 6 7 #include<math.h> 8 #define CRT_SECURE_NO_WARNINGS 9 10 11 int c1(int n) { 12 13 int i; 14 if (n == 1 || n == 0) { 15 return 0; 16 } 17 for (i = 2; i <= sqrt(n); i++) 18 { 19 if (n % i == 0) // 如果不为素数返回0 20 { 21 return 0; 22 } 23 } 24 return 1; // 反之则返回1 25 26 } 27 28 29 int c2(int n) { 30 31 int m = n; 32 33 int sum = 0; 34 while (m != 0) { 35 36 sum += m % 10; 37 m /= 10; 38 39 40 } 41 42 if (c1(sum) == 1) { 43 return 1; 44 } 45 else { 46 return 0; 47 } 48 49 } 50 51 52 int c3(int n) { 53 54 while (n != 0) { 55 56 int m = n % 10; 57 58 if (m == 2 || m == 3 || m == 5 || m == 7) { 59 return 1; 60 } 61 n /= 10; 62 } 63 return 0; 64 65 } 66 67 68 69 70 71 int main() 72 { 73 char s[10005]; 74 int arr[10005]; 75 int a1[10005]; 76 int a2[10005]; 77 int a3[10005]; 78 int a4[10005]; 79 while (scanf("%s", &s) != EOF) { 80 memset(arr, 0, sizeof(arr)); 81 82 int m; 83 scanf("%d", &m); 84 85 int len = strlen(s); 86 87 int quo = len / m; 88 89 int mod = len % m; 90 int cnt = 0; 91 92 for (int i = 0; i < len; i += m) { 93 94 int mul = 1; 95 int num = 0; 96 for (int j = i + m - 1; j >= i; --j) { 97 int t = s[j] - '0'; 98 num += t * mul; 99 mul *= 10; 100 101 102 } 103 arr[cnt++] = num; 104 105 } 106 107 108 109 //Print 110 if (mod != 0) { 111 int num = 0; 112 int mul = 1; 113 for (int i = len - 1; i >= quo * m; --i) { 114 int t = s[i] - '0'; 115 num += t * mul; 116 mul *= 10; 117 118 } 119 arr[cnt -1 ] = num; 120 121 /*for (int i = 0; i < quo + 1; ++i) { 122 printf("%d ", arr[i]); 123 }*/ 124 125 } 126 else if (mod == 0) { 127 /*for (int i = 0; i < quo; ++i) { 128 printf("%d ", arr[i]); 129 }*/ 130 } 131 132 int b1 = 0, b2 = 0, b3 = 0, b4 = 0; 133 int rmax = 0; 134 for (int i = 0; i < cnt; ++i) { 135 int n = arr[i]; 136 137 if (c1(n) == 1) { 138 139 a1[b1++] = n; 140 141 if (rmax < b1) { 142 rmax = b1; 143 } 144 145 146 } 147 else if (c2(n) == 1) { 148 a2[b2++] = n; 149 150 if (rmax < b2) { 151 rmax = b2; 152 } 153 154 } 155 else if (c3(n) == 1) { 156 a3[b3++] = n; 157 158 if (rmax < b3) { 159 rmax = b3; 160 } 161 162 163 } 164 else { 165 a4[b4++] = n; 166 167 168 169 if (rmax < b4) { 170 rmax = b4; 171 } 172 173 } 174 175 } 176 int k = 3; 177 for ( k = 3; k <= 101; k += 2) { 178 179 int room = (k - 1) / 2 * (k - 1) / 2; 180 181 if (rmax <= room) { 182 break; 183 } 184 185 186 187 } 188 //printf("k=%d", k); 189 int z1 = 0, z2 = 0, z3 = 0, z4 = 0; 190 191 192 // printf("ans:\n\n"); 193 194 for (int i = 0; i <k; ++i) { 195 196 197 for (int j = 0; j < k; ++j) { 198 199 200 if (i == j || i + j == k - 1) { 201 char p = '*'; 202 printf("%5c",p ); 203 204 } 205 else { 206 207 if (i < j && i + j < k - 1) { 208 209 210 if (z1 < b1) { 211 printf("%5d", a1[z1++]); 212 } 213 else { 214 printf("%5d",0); 215 } 216 217 } 218 219 if (i > j && i + j < k - 1) { 220 221 222 if (z2 < b2) { 223 printf("%5d", a2[z2++]); 224 } 225 else { 226 printf("%5d",0); 227 } 228 229 230 } 231 232 if (i < j && i + j > k - 1) { 233 234 if (z3 < b3) { 235 printf("%5d", a3[z3++]); 236 } 237 else { 238 printf("%5d",0); 239 } 240 241 } 242 if (i > j && i + j > k - 1) { 243 244 245 if (z4 < b4) { 246 printf("%5d", a4[z4++]); 247 } 248 else { 249 printf("%5d",0); 250 } 251 252 253 } 254 255 256 } 257 258 259 } 260 261 262 263 printf("\n"); 264 265 } 266 267 268 269 printf("\n"); 270 271 272 } 273 274 return 0; 275 }
标签:10,中南大学,int,2023,C语言,++,else,printf,include From: https://www.cnblogs.com/MasterYang/p/17142787.html