当前位置:网站首页>Codeup brushing notes - simple simulation
Codeup brushing notes - simple simulation
2022-08-03 22:03:00 【The first deep CQ】
1、A+B
题目描述
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.
现在请计算A+B的结果,并以正常形式输出.
输入
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9).
输出
请计算A+B的结果,并以正常形式输出,每组数据占一行.
-234,567,890 123,456,789
1,234 2,345,678
-111111101
2346912
#include<iostream>
using namespace std;
#include<cstring>
int main()
{
char s1[20],s2[20];
int len1,len2;
int a,b;
while(scanf("%s%s",s1,s2)!=EOF)
{
a=b=0;
len1=strlen(s1);
len2=strlen(s2);
for(int i=0;i<len1;i++)
{
if(s1[i]>='0'&&s1[i]<='9')
{
a=a*10+s1[i]-'0';//Turn the character array digital
}
}
if(s1[0]=='-')//负数取反
{
a=-a;
}
for(int i=0;i<len2;i++)
{
if(s2[i]>='0'&&s2[i]<='9')
{
b=b*10+s2[i]-'0';
}
}
if(s2[0]=='-')
{
b=-b;
}
cout<<a+b<<endl;
}
return 0;
}
2、特殊乘法
题目描述
写个算法,对2个小于1000000000的输入,求结果.特殊乘法举例:123 * 45 = 14 +15 +24 +25 +34+35
输入
两个小于1000000000的数
输出
输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果.
24 65
42 66666
3 67
66
180
39
#include<iostream>
using namespace std;
#include<cstring>
int main()
{
char s1[20],s2[20];
int len1,len2;
long sum;
while(scanf("%s%s",s1,s2)!=EOF)
{
sum=0;
len1=strlen(s1);
len2=strlen(s2);
for(int i=0;i<len1;i++)
{
for(int j=0;j<len2;j++)
{
if(isdigit(s1[i])&&isdigit(s2[j]))//判断数字
{
sum+=(s1[i]-'0')*(s2[j]-'0');
}
}
}
//One is a negative result is negative
bool flag= (s1[0]=='-'&&s2[0]!='-')||(s1[0]!='-'&&s2[0]=='-') ? true:false;
if(flag)
{
cout<<-sum<<endl;
}else
{
cout<<sum<<endl;
}
}
return 0;
}
3、比较奇偶数个数
题目描述
第一行输入一个数,为n,第二行输入n个数,这n个数中,If an even number is more than the odd,输出NO,否则输出YES.
输入
输入有多组数据.
每组输入n,然后输入n个整数(1<=n<=1000).
输出
If an even number is more than the odd,输出NO,否则输出YES.
1
67
7
0 69 24 78 58 62 64
YES
NO
#include<iostream>
using namespace std;
bool isOdd(int num)
{
return num%2==0 ? true:false;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int num,os=0,js=0;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
if(isOdd(num))
{
os++;
}else
{
js++;
}
}
if(js>os)
{
cout<<"YES"<<endl;
}else
{
cout<<"NO"<<endl;
}
}
return 0;
}
4、部分A+B
题目描述
正整数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的值.
3862767 6 13530293 3
3862767 1 13530293 8
399
0
#include<iostream>
#include<cstring>
using namespace std;
int count(string s,int x)
{
int cnt=0;
for(char c:s)
{
if(c-'0'==x)cnt++;
}
return cnt;
}
int toSum(int x,int num)
{
int sum=0;
for(int i=0;i<num;i++)
{
sum=sum*10+x;
}
return sum;
}
int main()
{
string sa,sb;
int a,b;
while(cin>>sa>>a>>sb>>b)
{
int cntA=count(sa,a);
int cntB=count(sb,b);
int pa=toSum(a,cntA);
int pb=toSum(b,cntB);
cout<<pa+pb<<endl;
}
return 0;
}
5、查找学生信息
题目描述
输入N个学生的信息,然后进行查询.
输入
输入的第一行为N,即学生的个数(N<=1000)
接下来的N行包括N个学生的信息,信息格式如下:
01 李江 男 21
02 刘唐 男 23
03 张军 男 19
04 王娜 女 19
然后输入一个M(M<=10000),接下来会有M行,代表M次查询,每行输入一个学号,格式如下:
02
03
01
04
输出
输出M行,每行包括一个对应于查询的学生的信息.
如果没有对应的学生信息,则输出“No Answer!”
#include<iostream>
using namespace std;
#include<cstring>
struct Student
{
string id;
string name;
string sex;
int age;
};
int main()
{
struct Student stu[1010];
int n;
string id;
string name;
string sex;
int age;
int m;
while(scanf("%d",&n)!=EOF)//Measured how set of test data,Subject did not say
{
for(int i=0;i<n;i++)
{
cin>>id>>name>>sex>>age;
stu[i].id=id;
stu[i].name=name;
stu[i].sex=sex;
stu[i].age=age;
}
cin>>m;
string s;
for(int i=0;i<m;i++)
{
bool flag=false;
cin>>s;
int j;
for(j=0;j<n;j++)
{
if(s==stu[j].id)
{
flag=true;
break;
}
}
if(flag)
{
cout<<stu[j].id<<" "<<stu[j].name<<" "<<stu[j].sex<<" "<<stu[j].age<<endl;
}else
{
cout<<"No Answer!"<<endl;
}
}
}
return 0;
}
边栏推荐
- 什么密码,永远无法被黑客攻破?
- 483. Smallest Good Base
- 【kali-漏洞扫描】(2.1)Nessus下载安装(上)
- FVCOM三维水动力、水交换、溢油物质扩散及输运数值模拟丨FVCOM模型流域、海洋水环境数值模拟方法
- C. Keshi Is Throwing a Party- Codeforces Global Round 17
- CAS:908007-17-0_Biotin-azide _生物素叠氮化物
- 距LiveVideoStackCon 2022 上海站开幕还有3天!
- 从0到1看支付
- HCIP第十六天
- What is the role and difference between buildscript and allprojects?
猜你喜欢

CAS:1620523-64-9_Azide-SS-biotin_biotin-disulfide-azide

嵌入式开发:嵌入式基础——代码和数据空间揭秘

Go开发工具GoLand V2022.2 来了——Go 工作区重大升级

距LiveVideoStackCon 2022 上海站开幕还有3天!

现网设备兼容SRv6网络演进
![[b01lers2020]Life on Mars](/img/d0/d5c9b7224542c8843ce29adc7ef713.png)
[b01lers2020]Life on Mars

斩获双奖|易知微荣获“2021中国数字孪生解决方案优秀供应商”“中国智能制造优秀推荐产品”双奖项!
![[N1CTF 2018]eating_cms](/img/09/3599d889d9007eb45c6eab3043f0c4.png)
[N1CTF 2018]eating_cms

一文带你了解软件测试是干什么的?薪资高不高?0基础怎么学?
![[3D检测系列-PV-RCNN] PV-RCNN论文详解、PV-RCNN代码复现、包含官网PV-RCNN预训练权重及报错问题](/img/81/c929864440dc36238b3cb1deb9f112.png)
[3D检测系列-PV-RCNN] PV-RCNN论文详解、PV-RCNN代码复现、包含官网PV-RCNN预训练权重及报错问题
随机推荐
[kali-vulnerability exploitation] (3.2) Metasploit basics (on): basic knowledge
21天打卡挑战学习MySQL——《MySQL工具的使用》第一周 第二篇
D - Project Planning--二分
优化查询(工作中)
封装、包、访问权限修饰符、static变量
pikachu Over permission 越权
YOLO之父宣布退出CV界,坦言无法忽视自己工作带来的负面影响
IDaaS 是什么?一文说清它的价值
B. Kalindrome Array
What is the role and difference between buildscript and allprojects?
FVCOM 3D Numerical Simulation of Hydrodynamics, Water Exchange, Dispersion and Transport of Oil Spills丨FVCOM Model Watershed, Numerical Simulation Method of Marine Water Environment
HCIP第十三天
超级实用网站+公众号合集
CAS: 773888-45-2_BIOTIN ALKYNE_生物素-炔基
剑指 Offer 07. 重建二叉树
[N1CTF 2018]eating_cms
[kali-vulnerability scanning] (2.1) Nessus download and installation (on)
编译器工程师眼中的好代码(1):Loop Interchange
JPA Native Query(本地查询)及查询结果转换
基于支持向量机的网络⼊侵检测系统的全面调查和分类