当前位置:网站首页>1169: 大整数(指针专题)
1169: 大整数(指针专题)
2022-04-21 09:06:00 【谦QIAN】
1169: 大整数(指针专题)
题目描述
输入3个非负大整数,位数不超过100位,按从小到大的顺序输出这三个整数。要求定义并使用如下函数比较两个大整数的大小。
int cmp(char *a,char *b)
{
//若大整数a大于b,返回1;
//若a小于b,返回-1;
// 若a与b相等,返回0
}
输入
输入有3行,每行输入一个大整数,位数不超过100位,输入不含前导0。
输出
输出3行,即排序后的3个大整数。
样例输入 Copy
1234567890123456789
99999999999999
111111111111111
样例输出 Copy
99999999999999
111111111111111
1234567890123456789
来源/分类
#include<stdio.h>
#include<string.h>
#define N 103
int cmp(char *a,char *b){
int m,n;
m=strlen(a);
n=strlen(b);
if(m>n) return 1;
else if(m<n) return -1;
else {
for(int i=0;i<n;i++){
if(a[i]>b[i]) return 1;
else if(a[i]<b[i]) return -1;
}
return 0;
}
}
int main(){
char a[3][N];
char *p;
p=(char *)malloc(sizeof(char)*N);
for(int i=0;i<3;i++){
gets(a[i]);
}
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
if(cmp(a[i],a[j])==1){
strcpy(p,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],p);
}
}
}
for(int i=0;i<3;i++){
puts(a[i]);
}
return 0;
}
版权声明
本文为[谦QIAN]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44500344/article/details/108011546
边栏推荐
- About shardingsphere
- 2022年山东省安全员C证考试题及模拟考试
- C language counting and sorting
- 方格分割【dfs】
- Notes of the most complete grain mall in the whole network_ 02. Introduction to the overall effect of the project (2022-04-02)
- Characteristics of interactive multimedia applications
- L2-026 小字辈 (25 分)
- Penetration practice - no echo rce thinkphp5 getshell
- JS -- closure
- 2017我也开始真正写CSDN博客(新浪网易转战CSDN)
猜你喜欢
随机推荐
kotlin 协程 lanch 详解
Penetration practice - no echo rce thinkphp5 getshell
Plan your own health problems
[(strongly pushed) Li Hongyi 2021 / 2022 spring machine learning course] unsupervised learning - linear methods
ARPU, the user of China Mobile, has re entered the rising channel, and the salary of employees has also increased steadily
物联网智能网关工控串口数据透传WiFi模块的选型
Performance analysis ideas
ShardingSphere简介
Handler asynchronous message passing mechanism (I) common basic usage of handler
Major programming languages and applications in 2022
Analyse de l'API d'interface de numéro personnel du robot Wechat PC
【ACM】131. 分割回文串
Template adaptation guide for toudabi thesis
C#100分秘籍 sduwh
Meizu, once expected to challenge apple, now lives by providing accessories for Apple users
加入log4j日志功能
渗透测试-获取系统FOFA关键字来刷洞
Pys1: Overview
[paper reading] [iccv 2021] rpnet: learning inner group relations on point clouds
【(强推)李宏毅2021/2022春机器学习课程】Unsupervised Learning - Linear Methods







![BUUCTF[极客大挑战 2019]EasySQL](/img/35/84422c6aea0c96f6cbcf8354729604.png)
