当前位置:网站首页>PAT 乙等 1016 C语言
PAT 乙等 1016 C语言
2022-06-23 04:11:00 【章鱼bro】
1016. 部分A+B (15)
正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。
现给定A、DA、B、DB,请编写程序计算PA + PB。
输入格式:
输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。
输出格式:
在一行中输出PA + PB的值。
输入样例1:3862767 6 13530293 3输出样例1:
399输入样例2:
3862767 1 13530293 8输出样例2:
0
思路:用俩个for循环分别统计出两个字符串中要统计字符的数目,以此计算出两个数,加个即可
一、起始变量
1.input1和input2分别为两个接受字符串的变量
2.a和b分别为要寻找的字符
3.countOfA和countOfB为对应两个字符出现的次数
4.A和B为最后对应的数字
二、运算
1.接受两个字符串和两个字符
2.用for循环遍历两个字符串,统计要寻找字符的出现的次数
3.计算出A和B
4.加和A和B输出
三、代码
#include "stdio.h"
#include "string.h"
#include "math.h"
typedef char string[10];
int main()
{
string input1,input2;
char a,b;//需要找的两个字符
int A = 0, B = 0;//最后用于计算和的A和B
scanf("%s %c %s %c",input1, &a, input2, &b);
char * p;
int countOfA = 0, countOfB = 0;
//统计a出现的次数
int i = 0;
for(i = 0; i < strlen(input1); i++)
{
if(input1[i] == a)
countOfA++;
}
//统计b出现的次数
for(i = 0; i < strlen(input2); i++)
{
if(input2[i] == b)
countOfB++;
}
//分别计算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;
}边栏推荐
- 2022年中国重卡智能化升级专题研究
- Webrtc[47] - a common way for webrtc to save YUV data
- 低成本5W无线充电器方案FS68001B简便充电芯片
- 基于SSM框架的借阅图书管理系统
- Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
- 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 performance of nonstandard sprintf code in different platforms
- SIFT feature point extraction
- How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
- 51万奖池邀你参战——第二届阿里云ECS CloudBuild开发者大赛来袭
猜你喜欢

Redis cache penetration solution - bloom filter

MySQL面试真题(二十四)——行列互换

ArcTime 制作中英文字幕视频

树莓派assert初步使用练习

Opportunities and challenges of digital collections from the perspective of technology development team

Leetcode 797: all possible paths

Skill self check | do you know these 6 skills if you want to be a test leader?

FS4059A与FS5080E充电芯片的区别

Raspberry pie assert preliminary exercise

FS2119A同步升压IC输出3.3V和FS2119B同步升压IC输出5V
随机推荐
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
知识点滴 - 折叠锻打和大马士革钢
Arctime makes Chinese and English subtitle video
Wechat applet: future wife query generator
[opencv450] image subtraction, binarization, threshold segmentation
数字藏品赋能实体产业释放了哪些利好?
STC 32位8051单片机开发实例教程 一 开发环境搭建
英集芯IP5566带TYPE-C口3A充放快充移动电源5w无线充二合一方案SOC
Redis cache penetration solution - bloom filter
【owt】owt-client-native-p2p-e2e-test vs2017构建 6:修改脚本自动生成vs工程
Wechat applet: an artifact for calculating the full amount of orders
Composite API
Software project management 8.4 Software project quality plan
App automated test appium advanced
fastjson中的@JSONField注解
Ansible 使用普通用户管理被控端
jvm: 方法重载时,具体调用哪个方法,是由传入参数的静态类型来决定的,而不是由参数的实际类型来决定
英集芯ip6806无线充电方案5W过Qi认证外围精简14颗器件
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
visdom的使用