首页 > 代码库 > Hashmat the Brave Warrior

Hashmat the Brave Warrior

Hashmat the Brave Warrior

XX自己有士兵a人, 敌军有士兵b人,自己的士兵永远比敌军少, 求对方比自己多多少人。       (虽说要从头刷,但是这样的还是太水了吧 2333333

喜闻乐见的错了因为2^32爆了int。。。These two numbers in each line denotes the number of soldiers in Hashmat‘s army and his opponent‘s army or vice versa

1 #include <cstdio>2 int main() {3      long long a, b;4      while (scanf("%lld%lld", &a, &b) != EOF) {5          long long ans = b - a > 0 ? b - a : a - b;6          printf("%lld\n", ans);7      }8      return 0;9 }
View Code

 

Rotating Sentences

把一篇文章顺时针旋转90° 看起来挺简单操作起来有点难度。。。               关键的地方在于如果是文章结尾,用空格补全    (读题的时候没读出这个意思)

#include <cstdio>#include <cstring>const int N = 110;char mapp[N][N];int len[N];int main() {    //freopen("in.txt", "r", stdin);    int i = 0, maxlen = 0;    memset(mapp, \0, sizeof(mapp));    while (gets(mapp[i]) != NULL) i++;    for (int j = 0; j < i; j++) {        len[j] = strlen(mapp[j]);        maxlen = maxlen > len[j] ? maxlen : len[j];    }    for (int j = 0; j < maxlen; j++) {        for (int k = i-1; k >= 0; k--) {            if (j >= len[k]) putchar( );            else putchar(mapp[k][j]);        }        puts("");    }    return 0;}
View Code

 

Hashmat the Brave Warrior