Mar 22, 2011

一道笔试题

#include <stdio.h>
#include <string.h>

char *shift_r(const char *src, const int n, char *dst)
{
    int i, len;

    if (src == NULL || (len = strlen(src)) == 0)
        return (dst = NULL);

    for (i = 0; i < len; i++)
        dst[(i+n)%len] = src[i];
    dst[i] = '\0';

    return dst;
}

int main(int argc, char *argv[])
{
    const char *src = "abcdef";
    char dst[80];
    const int n = 2;

    printf("%s\n%s\n", src, shift_r(src, n, dst));

    return 0;
}
好吧, 这个也算 ... 口头描述这个真没劲 ...
#!/bin/bash

echo "testing for ..."
for ((i=0; i < 10; i++))
do
    echo $i
done

echo "testing while ..."
i=0
while [ $i -lt 10 ]
do
    echo $i
    i=$((i+1))
done

No comments:

Post a Comment

您的评论将使我blog更有动力~