题目链接: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. R You Ready?——大数据时代下优雅、卓越的统计分析及绘图环境

    作者按:本文根据去年11月份CSDN举办的“大数据技术大会”演讲材料整理,最初发表于2012年2月期<程序员>杂志. 0  R 的安装

  2. css3动画由浅入深总结

    阅读目录 一:过渡动画---Transitions 二:Animations功能 三:translate(tx,ty) 四:scale(x,y) 五:rotate(x): 5.1:skew(x,y): ...

  3. 黑客攻防技术宝典Web实战篇(一)Web应用程序技术基础

    在开展Web应用程序渗透测试之前请先了解下面列出的这些内容,如果不是很懂的话,请读David Gourley & Brian Totty的HTTP权威指南也叫HTTP:The Definiti ...

  4. UML浅析

    UML概述 UML (Unified Modeling Language)为面向对象软件设计提供统一的.标准的.可视化的建模语言.适用于描述以用例为驱动,以体系结构为中心的软件设计的全过程. UML模 ...

  5. jquery获取文本框的内容

    使用jquery获取文本框的内容有以下几种: 1.根据ID取值(id属性): // javascript <script type="text/javascript"> ...

  6. Android手机如何通过USB共享网络给Mac?

    最近网络挂了,mac不能上网查资料,心情非常毛躁,急切寻求用mac蹭WiFi的方法. 没有找到电脑端破解WiFi密码的软件,手头的Android手机没有root,也无法查看WiFi密码--->破 ...

  7. iOS开发——网络篇——文件下载(NSMutableData、NSFileHandle、NSOutputStream)和上传、压缩和解压(三方框架ZipArchive),请求头和请求体格式,断点续传Range

    一.小文件下载 NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/resources/images/minion ...

  8. 如何安装最新的 XFCE 桌面?

    导读 Xfce 是一款针对 Linux 系统的现代化轻型开源桌面环境,它在其他的类 Unix 系统上,比如 Mac OS X. Solaries. *BSD 以及其它几种上也能工作得很好.它非常快并以 ...

  9. 在应用中嵌入Python:转

    在应用中嵌入Python 前面的章节讨论如何扩展Python,如何生成适合的C库等.不过还有另一种情况:通过将Python嵌入C/C++应用以扩展程序的功能.Python嵌入实现了一些使用Python ...

  10. [COJ0528]BJOI幸运数

    [COJ0528]BJOI幸运数 试题描述 输入 见"试题描述" 输出 见"试题描述" 输入示例 见"试题描述" 输出示例 见"试 ...