1、3261:【例43.2】 IP地址
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
scanf("%d.%d.%d.%d",&a,&b,&c,&d);
printf("%02x%02x%02x%02x",a,b,c,d);
return 0;
}
2、3262:【例43.3】 转二进制
/*
3262:【例43.3】 转二进制
http://bas.ssoier.cn:8086/problem_show.php?pid=3262
[SSL_CHX][2021-08-19]转二进制
https://blog.csdn.net/Edwin_CHX/article/details/119801608
*/
#include<bits/stdc++.h>
using namespace std;
int a[10000000];
int main()
{
int n,s=1;
cin>>n;
while(n>0)
{
a[s]=n%2;
s++;
n/=2;
}
for(int i=1;i<s;i++)
{
cout<<a[i];
}
return 0;
}
/*
3262:【例43.3】 转二进制
http://bas.ssoier.cn:8086/problem_show.php?pid=3262
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while( n )
{
cout<<n%2;
n/=2;
}
return 0;
}
3、3263:练43.1十进制转八进制
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
printf("%o\n", a); // 八进制
return 0;
}
4、3264:练43.2十进制转十六进制
#include <iostream>
using namespace std;
long long n, x;
string s;
string t = "0123456789ABCDEF";
int main(){
/*
条件:
n是一个不超过18位的正整数。
注意:
int最多表达到 2^31 - 1,10位整数。
long long 最多表达到 2^63 - 1,19位整数。
思路:
逆序存储到字符串时要注意:
整数 0 ~ 9,转换为字符 '0' ~ '9',x + '0'
整数 10 ~ 15,转换为字符 'A' ~ 'F',x + 'A' - 10 或 x + 55
*/
cin >> n;
while(n != 0){
x = n % 16;
// 将 n % 16 转换为字符逆序存入 s
s = t[x] + s;
n = n / 16;
}
if(s == ""){
cout << 0;
}else{
cout << s;
}
}
/*
3264:练43.2十进制转十六进制
http://bas.ssoier.cn:8086/problem_show.php?pid=3264
https://codeleading.com/article/39485805289/
*/
#include <iostream>
using namespace std;
long long n, x;
string s;
string t = "0123456789ABCDEF";
int main(){
/*
条件:
n是一个不超过18位的正整数。
注意:
int最多表达到 2^31 - 1,10位整数。
long long 最多表达到 2^63 - 1,19位整数。
思路:
逆序存储到字符串时要注意:
整数 0 ~ 9,转换为字符 '0' ~ '9',x + '0'
整数 10 ~ 15,转换为字符 'A' ~ 'F',x + 'A' - 10 或 x + 55
*/
cin >> n;
while(n != 0){
x = n % 16;
// 将 n % 16 转换为字符逆序存入 s
s = t[x] + s;
n = n / 16;
}
if(s == ""){
cout << 0;
}else{
cout << s;
}
}
5、3265:练43.3算进制
/*
3265:练43.3算进制
http://bas.ssoier.cn:8086/problem_show.php?pid=3265
*/
#include<bits/stdc++.h>
using namespace std;
char maxc,ch;
int main()
{
cin>>maxc;
while(cin>>ch)
{
if(ch>maxc) maxc=ch;
}
if(maxc>='0' && maxc<='9') cout<<maxc-'0'+1;
else cout<<maxc-'A'+11;
return 0;
}
6、3266:【例44.1】 输出二进制补码
/*
3266:【例44.1】 输出二进制补码
http://bas.ssoier.cn:8086/problem_show.php?pid=3266
https://blog.csdn.net/zhunubi/article/details/125958260
*/
#include<bits/stdc++.h>
using namespace std;
int a,b[10000],l;
int main(){
cin>>a;
if(a>=0){
while(a>0){
b[l++]=a%2;a=a/2;}l=32;b[l-1]=0;}else{a=abs(a);
while(a>0){
b[l++]=a%2;a=a/2;}l=32;b[l-1]=1;
for(int i=l-2;i>=0;i--){
if(b[i]==0){b[i]=1;}else{b[i]=0;}}
b[0]+=1;
if(b[0]>=2){
b[0]=b[0]%2;
for(int i=1;i<l;i++){
b[i]+=1;
if(b[i]>=2){b[i]=b[i]%2;}else{break;}}}}
for(int i=l-1;i>=0;i--){cout<<b[i];}
return 0;
}
7、3267:【例44.2】 1的个数
【C语言】1的个数
统计二进制中1的个数(3种方法)
/*
3267:【例44.2】 1的个数
http://bas.ssoier.cn:8086/problem_show.php?pid=3267
https://blog.csdn.net/li_wen_zhuo/article/details/104587559
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int lowbit(int x)
{
return x&(-x);
}
int main()
{
int n,k=0;
cin>>n;
while(n) {n-=lowbit(n); k++;}
cout<<k;
return 0;
}
8、3268:【例44.3】 内码对称
1080: 内码对称
题目 1189: 内码对称
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,ans[1000+10],num=0;
cin>>n;
bitset<32> a(n);
for(int i=0,j=31;i<j;i++,j--)
{
if( a[i]!=a[j] )
{
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
return 0;
}
9、3269:练44.1 比特童币
第59课 比特童币 《小学生C++趣味编程》
《小学生C++趣味编程》第59课 比特童币_四重循环
/*
第59课 比特童币(完整)《小学生C++趣味编程》
试编一程序,输出(0)2至(1111)2之间所有的整数及对应的十进制数。
*/
#include<iostream>
using namespace std;
int main()
{
int a1,a2,a3,a4,n;
for(a4=0;a4<=1;a4++)
for(a3=0;a3<=1;a3++)
for(a2=0;a2<=1;a2++)
for(a1=0;a1<=1;a1++)
{
n=a4*8+a3*4+a2*2+a1*1;
cout<<a4<<a3<<a2<<a1<<"B "<<n<<endl;
}
return 0;
}
/*
作业:
1098:质因数分解
http://ybt.ssoier.cn:8088/problem_show.php?pid=1098
1099:第n小的质数
http://ybt.ssoier.cn:8088/problem_show.php?pid=1099
1100:金币
http://ybt.ssoier.cn:8088/problem_show.php?pid=1100
*/
10、3270:练44.2 二进制转化为十进制
/*
3416:【例72.1】 二进制转化为十进制
http://bas.ssoier.cn:8086/problem_show.php?pid=3416
信息学奥赛一本通-编程启蒙 解题目录
https://blog.csdn.net/sxj_c/category_12384636.html
怎么把二进制转换为十进制(编程启蒙3416:【例72.1】 二进制转化为十进制)
https://blog.csdn.net/ptyz306/article/details/132023614
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,cnt=0,ans=0;
cin>>n;//n表示有几位数
string a;
cin>>a;//用字符串来读取二进制数
for(int i=a.size()-1;i>=0;i--){//从最后一位往前算
ans+=int(a[i]-48)*pow(2,cnt);
/*这里,ans表示的是十进制数,我们是从后往前,
把二进制每一位代表的数都加起来,这里,cnt
代表的是当前计算到了倒数第cnt+1位,那这一位的
一个1就代表2^cnt(比如cnt=0,在计算倒数第一位)
时,这里的一个1就代表2^0(等于1),pow函数用于
计算2^cnt,int(a[i]-48)是将字符串的某一位改为数字
*/
cnt++;//接下来要计算下一位,那么cnt也要+1
}
cout<<ans;//输出答案,完美的解决了这个问题
return 0;
}
有哪些信息学奥赛相关的比赛和考试
中小学信息学相关比赛汇总(C++类)
信息学奥赛学习、训练、测试的顺序,思路及方法
信息学奥赛学习规划 国内顶尖信息学奥赛名校训练模式 信奥中的数学
信息学奥赛训练体系(2023.02.21)
CSP-J2 CSP-S2 复赛 第2轮 比赛技巧-做题策略与时间分配、容易犯错误汇总 NOI Linux2.0文件操作等
CSP-J2 CSP-S2 复赛 第2轮 比赛技巧-做题策略与时间分配、容易犯错误汇总 NOI Linux2.0文件操作等-CSDN博客
NOI Linux 2.0的简单用法、CSP-J2、CSP-S2复赛注意事项等
创新、创新思维书籍(2023.10。10)
调试与对拍
信奥中的“骗”分神技 ---“打表”
【NOI2022】PV「什么是信息学精神?」
小学生信奥赛前学习规划、信奥学习规划
小学生讲C++(2023.12.03)
宝宝的C++、小学生C++启蒙、小学生C++入门
宝宝的C++、小学生C++启蒙、小学生C++入门-CSDN博客
编程启蒙系列书籍(2023.11.24)