User Chris118ta

Member for: 2 years (since Sep 21, 2017)
Type: Approved user
Student for 2017-1 CSIEB0020-Introduction to Computer Programming (I)
Student for 2017-2 CSIEB0040 - Introduction to Computer Programming (II)
Student for 2017-2 GC_6452AL Fundamental Computer Programming (Python)
Student for 2018-1 CSIEB0100 - Data Structures
Full name:
Location:
Website:
About:

Activity by Chris118ta

Score: -284 points (ranked #2,557)
Questions: 0
Answers: 227
Comments: 1
Voted on: 0 questions, 0 answers
Gave out: 0 up votes, 0 down votes
Received: 2 up votes, 0 down votes

Wall for Chris118ta

#include<iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;

int a[10];

Compute(int n){
    int i,j;
    char s[10];
    for(i = 0 ; i < 10 ; i++)
        a[i] = 0;
    for(i = 1 ; i <= n ; i++)
    {
        sprintf(s,"%d",i);  //將數字轉成字串
        for(j = 0 ; j < strlen(s) ; j++)
            a[s[j]-48]++;   //因為轉成字串後事ASCII碼 所以要-48才會是正確的數字
    }
}

int main(){
    int x,n;
    cin >> x;
    while(x--)
    {
        cin >> n;
        Compute(n);
        for(int i=0 ; i<9 ; i++)
            cout << a[i] << " ";
        if(x != 0)
            cout << a[9] << endl;
        else
            cout << a[9];
    }
}
May 12, 2018 by Chris118ta
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100

int main()
{

    char str[1000], reverse[1000];
    int len, i, index=0, wordStart, wordEnd;

    fgets(str,1000,stdin);

    len   = strlen(str);


    wordStart = len - 1;
    wordEnd   = len - 1;

    while(wordStart > 0)
    {

        if(str[wordStart] == ' ')
        {

            i = wordStart + 1;
            while(i <= wordEnd)
            {
                reverse[index] = str[i];

                i++;
                index++;
            }
            reverse[index++] = ' ';

            wordEnd = wordStart - 1;
        }

        wordStart--;
    }


    for(i=0; i<=wordEnd; i++)
    {
        reverse[index] = str[i];
        index++;
    }

    reverse[index] = '\0';

    //printf("%s", reverse);
    for (i=0;i<strlen(reverse);i++){
        if (reverse[i]=='\n')
            ;
        else
            printf("%c",reverse[i]);
    }
return 0;
}
Apr 25, 2018 by Chris118ta
#include<stdio.h>
#include<string.h>

int main() {
    char in[1000];
    char a[26];
    int i=0,j=0,len,largest=0;
    for(;i<1000;i++) {
        in[i]=0;
        a[i]=0;
    }
    fgets(in,1000,stdin);
    len=strlen(in);
    for(i=0;i<1000;i++) {
        if(in[i]!=0) {
            j=in[i]-97;
            a[j]++;
        }
    }
    for(i=0;i<26;i++) {
        if(a[i]>largest) {
            largest=a[i];
        }
    }
    printf("%d", largest);
}
Apr 25, 2018 by Chris118ta
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char a[100];
    do
    {
        scanf("%s",a);
    }while(strlen(a) < 3);

    char b;
    scanf(" %c",&b);

    int i,found = 0;
    for(i = 0 ; i < strlen(a) ; i++)
    {
        if(a[i] == b && a[i+1] == b && a[i+2] == b)
        {
            printf("%d",i);
            found = 1;
            break;
        }
    }
    if(found == 0)
        printf("Not found");



    return 0;
}
Apr 25, 2018 by Chris118ta
9,132 questions
80,613 answers
55,967 comments
2,582 users