题目链接:http://codeforces.com/problemset/problem/616/A

题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小

模拟即可。提供两个版本,数组版本 & 指针版本。

  (1)数组版本(短的字符串从高位处补0,直到跟长的字符串长度相同)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6 + ;
char a[maxn], b[maxn];
int rev_a[maxn], rev_b[maxn]; int cmp(int len)
{
int f = ; // 0: a=b; 1: a>b; 2: a<b
// 比较的时候要从高位比起,存储的时候是从低位开始存的
for (int i = len-; i >= && !f; i--) {
if (rev_a[i] > rev_b[i]) {
f = ;
}
else if (rev_a[i] < rev_b[i]) {
f = ;
}
}
return f;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s%s", a, b) != EOF) {
int la = strlen(a);
int lb = strlen(b); for (int i = ; i < la; i++) {
rev_a[la-i-] = a[i]-'';
} for (int i = ; i < lb; i++) {
rev_b[lb-i-] = b[i]-'';
} int flag = ;
// 保证比较的字符串长度相等, 0补上
if (la < lb) { // la < lb
for (int i = ; i < lb-la; i++) {
rev_a[la+i] = ;
}
flag = cmp(lb);
}
else { // la >= lb
for (int i = ; i < la-lb; i++) {
rev_b[lb+i] = ;
}
flag = cmp(la);
}
if (flag == ) puts(">");
else if (flag == ) puts("<");
else puts("=");
}
return ;
}

  (2)指针版本(过滤前缀0之后,再逐位比较大小)

 /*
指针版本
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6 + ;
char a[maxn], b[maxn]; int cmp(char *s1, char *s2)
{
// 过滤前缀 0
while (*s1 == '') {
s1++;
}
while (*s2 == '') {
s2++;
} int l1 = strlen(s1);
int l2 = strlen(s2);
if (l1 > l2) {
return '>';
}
else if (l1 < l2) {
return '<';
}
// a,b长度相等(l1 = l2)
for (int i = ; i < l1; i++) {
if (*s1 < *s2) { // 指针指向的值
return '<';
}
else if (*s1 > *s2) {
return '>';
}
s1++; // 指针右移一位
s2++;
}
return '=';
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s%s", a, b) != EOF) {
printf("%c\n", cmp(a, b));
}
return ;
}

codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟

    A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...

  4. Educational Codeforces Round 5 A. Comparing Two Long Integers

    A. Comparing Two Long Integers time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  5. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  6. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  7. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

    E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

随机推荐

  1. hadoop 集群 加入一个新的存储节点和删除一个计算节点需要刷新集群状态命令

    加入一个新的存储节点和删除一个计算节点需要刷新集群状态命令 方式1:静态添加datanode,停止namenode方式 1.停止namenode 2.修改slaves文件,并更新到各个节点3.启动na ...

  2. 【python网络编程】使用rsa加密算法模块模拟登录新浪微博

    一.基础知识 http://blog.csdn.net/pi9nc/article/details/9734437 二.模拟登录 因为上学期参加了一个大数据比赛,需要抓取数据,所以就想着写个爬虫抓取新 ...

  3. laravel中间件-----------middleware

    middleware中间件 是访问到达服务器后在被对应的路由处理之前所经过的一层过滤层,故称中间件. 中间件是存放在app\http\middleware中,需要定一个 handle 处理方法,在ha ...

  4. autolayout的各种坑

    xocde7的autolayout 在viewDidLoad之前, 使用frame改变布局是没有用的, 简单的视图才可以使用autolayout, 稍微复杂写的都要使用代码来编写 获取当前view的宽 ...

  5. Oracle sysdate 时间加减

    加法 select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate,add_months(sysdate,1 ...

  6. jQuery lazyload插件详解和问题解答

    lazyload插件用于图片延迟加载,节省服务器带宽,减少服务器请求次数,提高网站的页面加载速度,用于网站性能优化,只有当图片在窗口可视范围内时才向服务器请求: 参数: threshold:设置距离窗 ...

  7. iOS9开发者测试版下载地址(系转载)

    将链接复制后,打开迅雷即可下载!请根据自己的手机型号下载.不需要udid绑定.开发者账号,下载后直接升级即可.请根据自己的手机型号将链接复制 打开迅雷 点击立即下载即可.不过好像Mac版的迅雷下载不了 ...

  8. DMZ

    DMZ是英文“demilitarized zone”的缩写,中文名称为“隔离区”,也称“非军事化区”.它是为了解决安装防火墙后外部网络的访问用户不能访问内部网络服务器的问题,而设立的一个非安全系统与安 ...

  9. POJ 3641 快速幂+素数

    http://poj.org/problem?id=3641 练手用,结果念题不清,以为是奇偶数WA了一发 #include<iostream> #include<cstdio> ...

  10. Eclipse中项目红叉但找不到错误解决方法

    首先windows-show view-problems 根据地址查找错误 若提示: Description    Resource    Path    Location    TypeJava c ...