当前位置:网站首页>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;
}
边栏推荐
- 一文带你了解软件测试是干什么的?薪资高不高?0基础怎么学?
- XSS practice - cycle and two cycle problem at a time
- 《强化学习周刊》第56期:GraphIRL、REDEEMER & 眼科强化学习的潜在研究
- XSS练习---一次循环和两次循环问题
- 优化查询(工作中)
- CAS: 1192802-98-4 _uv cracking of biotin - PEG2 - azide
- XSS testing
- 剑指 Offer 16. 数值的整数次方
- XSS online shooting range---haozi
- YOLO之父宣布退出CV界,坦言无法忽视自己工作带来的负面影响
猜你喜欢
随机推荐
FVCOM三维水动力、水交换、溢油物质扩散及输运数值模拟丨FVCOM模型流域、海洋水环境数值模拟方法
6. XML
Data_web(八)mysql增量同步到mongodb
Security Fundamentals 8 --- XSS
『百日百题 · 基础篇』备战面试,坚持刷题 第四话——循环语句!
Go开发工具GoLand V2022.2 来了——Go 工作区重大升级
一些思考:腾讯股价为何持续都低
XSS练习---一次循环和两次循环问题
Flink--Join以及Flink函数
DO280管理和监控OpenShift平台--资源限制
for循环练习题
[kali-vulnerability scanning] (2.1) Nessus lifts IP restrictions, scans quickly without results, and plugins are deleted (middle)
嵌入式系统:时钟
易基因|RNA m5C甲基化测序(RNA-BS)技术介绍
趣链的产品构架
【kali-漏洞扫描】(2.1)Nessus下载安装(上)
AI首席架构师13-AICA-智能文档分析技术在行业场景中的应用
October 2019 Twice SQL Injection
距LiveVideoStackCon 2022 上海站开幕还有3天!
L2-029 特立独行的幸福









