当前位置:网站首页>Pat class B 1016 C language
Pat class B 1016 C language
2022-06-23 05:57:00 【Octopus bro】
1016. part A+B (15)
Positive integer A Of “DA( by 1 An integer ) part ” Defined by A All in DA A new integer composed of PA. for example : Given A = 3862767,DA = 6, be A Of “6 part ”PA yes 66, because A There is 2 individual 6.
Now given A、DA、B、DB, Please write a program to calculate PA + PB.
Input format :
The input is given in turn on a line A、DA、B、DB, Space between , among 0 < A, B < 1010.
Output format :
Output in one line PA + PB Value .
sample input 1:3862767 6 13530293 3sample output 1:
399sample input 2:
3862767 1 13530293 8sample output 2:
0
Ideas : Use two for Loop to count the number of characters to be counted in the two strings , So we can calculate two numbers , Add one
One 、 Starting variable
1.input1 and input2 These are two variables that accept strings
2.a and b The characters to be found
3.countOfA and countOfB Is the number of occurrences corresponding to two characters
4.A and B Is the last corresponding number
Two 、 operation
1. Accept two strings and two characters
2. use for Loop through two strings , Count the number of occurrences of characters to be searched
3. To calculate the A and B
4. Add and A and B Output
3、 ... and 、 Code
#include "stdio.h"
#include "string.h"
#include "math.h"
typedef char string[10];
int main()
{
string input1,input2;
char a,b;// Two characters to find
int A = 0, B = 0;// Finally used to calculate sum A and B
scanf("%s %c %s %c",input1, &a, input2, &b);
char * p;
int countOfA = 0, countOfB = 0;
// Statistics a Number of occurrences
int i = 0;
for(i = 0; i < strlen(input1); i++)
{
if(input1[i] == a)
countOfA++;
}
// Statistics b Number of occurrences
for(i = 0; i < strlen(input2); i++)
{
if(input2[i] == b)
countOfB++;
}
// Separate calculation A、B
for(i = 0; i < countOfA; i++)
{
A += (a - '0') * pow(10, i);
}
for(i = 0; i < countOfB; i++)
{
B += (b - '0') * pow(10, i);
}
printf("%d",A + B);
return 0;
}边栏推荐
- App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
- jvm-02.有序性保证
- MySQL面试真题(二十五)——常见的分组比较场景
- Analysis on the problems and causes of digital transformation of manufacturing industry
- Kotlin android简单Activity跳转、handler和thread简单配合使用
- New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!
- 三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
- JS interview question - anti shake function
- The difference between SaaS software and traditional software delivery mode
- The construction of digital factory can be divided into three aspects
猜你喜欢

Wechat applet; AI intelligent dubbing assistant

How to move the software downloaded from win11 app store to the desktop

A bit of knowledge - folding forging and Damascus steel

如何指定pig-register项目日志的输出路径

jvm-05.垃圾回收

技术开发团队视角看到的数字藏品机遇与挑战

Real MySQL interview question (23) -- pinduoduo ball game analysis

Wireshark TS | 视频 APP 无法播放问题

Wireshark TS | video app cannot play

MySQL面试真题(二十一)——金融-贷款逾期
随机推荐
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
Pat class B 1012 C language
C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
Leetcode topic resolution divide two integers
PAT 乙等 1026 程序运行时间
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
The performance of nonstandard sprintf code in different platforms
jvm-02. Guarantee of orderliness
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
使用链表实现两个多项式相加和相乘
The difference between SaaS software and traditional software delivery mode
ssm项目搭建
What is the magic of digital collections? Which reliable teams are currently developing
How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
最优传输理论下对抗攻击可解释性
编址和编址单位
Digital collections - new investment opportunities
云原生数据库是未来
Android handler memory leak kotlin memory leak handling
jvm-06. Garbage collector