1016. 部分A+B
题目截图:
思路:
字符串查找。
代码:
1 /* 2 1016. 部分A+B 3 */ 4 5 #include <stdio.h> 6 #include <string.h> 7 #include <math.h> 8 #include <stdlib.h> 9 #include <time.h> 10 11 int main() { 12 char a[12]; 13 char d; 14 int PA=0, PB=0, dNum=0; // dNum存储d重复次数 15 scanf("%s %c", a, &d); 16 int i; 17 for(i=0; i<strlen(a); ++i) { // 遍历 18 if(a[i] == d) { 19 dNum++; 20 } 21 } 22 for(i=0; i<dNum; ++i) { // 计算 PA 23 PA = PA*10+(d-'0'); 24 } 25 dNum=0; 26 scanf("%s %c", a, &d); 27 for(i=0; i<strlen(a); ++i) { 28 if(a[i] == d) { 29 dNum++; 30 } 31 } 32 for(i=0; i<dNum; ++i) { // 计算 PB 33 PB = PB*10+(d-'0'); 34 } 35 printf("%d", PA+PB); // 输出 PA+PB 36 37 return 0; 38 }
相关推荐
89243453 2020-08-24
Erick 2020-08-21
earthhouge 2020-07-19
klarclm 2020-06-14
拉斯厄尔高福 2020-06-02
Jaystrong 2020-06-02
hongsheyoumo 2020-06-02
twater000 2020-05-30
adonislu 2020-05-17
Haopython 2020-05-09
浅梦墨汐 2020-05-12
shenwenjie 2020-05-09
fengjing81 2020-05-08
lihuifei 2020-05-04
wbczyh 2020-05-03
LychieFan 2020-04-30
luckymaoyy 2020-04-25
Cypress 2020-04-25