Practical Address:https://ac.nowcoder.com/acm/admin/self/rejudge?contestId=72883

A. Swap

#include <stdio.h>

void swapIntegers(int* a, int *b) {
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
}
int main() {
    int a, b;
    scanf("
    swapIntegers(&a, &b);
    printf("
    return 0;
}

B. Bubble sort

#include <stdio.h>
#define N 100

int arr[N], n;
void sort(int* arr, int n) {
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n - 1; ++j) {
            if(arr[j] > arr[j + 1]) {
                arr[j] ^= arr[j + 1];
                arr[j + 1] ^= arr[j];
                arr[j] ^= arr[j + 1];
            }
        }
    }
}
int main () {
    scanf("
    for(int i = 0; i < n; ++i) scanf("
    sort(arr, n);
    for(int i = 0; i < n; ++i) printf("
    return 0;
} 

C. Substr

#include <stdio.h>
#define N 100

int l, len;
char s[N], sub[N];
void substr(char* s, int p, int len, char* sub) {
    int idx = 0;
    while(len--) sub[idx++] = s[l++];
    sub[idx] = '\0';
}
int main () {
    scanf("
    substr(s, l, len, sub);
    printf("
    return 0;
} 

D. Append

#include <stdio.h>
#include <string.h>
#define N 100

char a[N], b[N], s[N];
void concatenate(char* a, char* b, char* s) {
    int idx = 0;
    for(int i = 0; i < strlen(a); ++i) s[idx++] = a[i];
    for(int i = 0; i < strlen(b); ++i) s[idx++] = b[i];
    s[idx] = '\0';
}
int main () {
    scanf("
    concatenate(a, b, s);
    printf("
} 

E. Narcissistic

#include <stdio.h>
#define N 20

int cnt = N, num;
int qmi(int p, int a) {
    int res = 1, t = p;
    while(a) {
        if(a & 1) res *= t;
        t *= t;
        a >>= 1;
    }
    return res;
}
int narcissistic(int num) {
    int t = num, digit = 0, ans = 0;
    while(t) t /= 10, ++digit;
    t = num;
    while(t) {
        ans += qmi(t
        t /= 10;
    }
    return ans == num;
}
int main () {
    while(cnt) {
        if(narcissistic(num)) {
            printf("
            --cnt;
        }
        ++num;
    }
    return 0;
}
分类: C/C++String

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

友情链接:Ctips' blog, Colza’s blog

站点状态:Status