anonymous No title
C
#include <iostream>
#include <algorithm>
using namespace std;

const int n=6, W=8;
const int w[n] = {2,1,3,2,1,5}, v[n]={3,2,6,1,3,85};

int dp[10][10];

int rec(int i, int cap) {
    if (dp[i][cap] != -1) {
        return dp[i][cap];
    }

    int res;
    if (i == n) {
        res = 0;
    } else if (cap < w[i]) {
        res = rec(i + 1, cap);
    } else {
        res = max(
            rec(i + 1, cap),
            rec(i + 1, cap - w[i]) + v[i]
        );
    }
    return dp[i][cap] = res;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cout << rec(0, W) << endl;
}
anonymous No title
C
user table
    ID
    name
    userrank (どのプランか)
    age
    furiganalevel
    password (仮パスワードであるか、いる?)
    bikouran (備考欄、adminしか見れない)
    struct midoku (未読フラグ) {
        foradmin
        chat
        honnnotomo
    }
    charsum
    readtimesum
    continuedays
    
recommend table
    ID
    userID
    bookID
    state

admin table
    ID
    password

minilesson table
    ID
    name
    startlessontextID

lessonText table
    ID
    level1text (これ振り仮名のせいでlevelが三つある)
    level2text
    level3text
    lessonanswerID (can null)
    nexttextID(endflag兼ねれる?) (can null)
    previoustextID (can null)


lessonAnswer table(ごめんなさいn択のやり方がわからなかった)
    ID
    default (key1~5でない時)
    text LV1~3
    key1 (can null) (子供たちは"A"を"Aです"とか言いがちなので前方一致で判定がいい)
    text LV1~3
    key2 (can null)
    text LV1~3
    key3~5 (can null)

talk table
    ID
    userID (誰に、または誰が話しているか)
    type (user,lesson,lessonAnswer,otherReview,admin)
    text (or lessontextIDandLevel or bookID)
    time


readlog
    ID
    userID
    bookID(isbnの方がよい?)
    time
    readtime
    end //読み切れたか(はい、いいえ、途中までよんだ)
    struct review{
        difficulity
        like
        text
    }



イリーナ No title
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct geotag{
  char* id;
  char* shot_time;
  char* latitude;
  char* longitude;
  char* url;

};

int main(int argc, char** argv){

	FILE *fp_tag;
	
	char *tag_filename = "tag.csv";
	
	fp_tag = fopen(tag_filename,"r");
	if(fp_tag == NULL){
		printf("file open error \n");
		return -1;
		}
	
	int limit = 0;
	char *buf;
	buf = (char *)malloc(sizeof(char) * 2000); 
	char id[100];
	struct geotag g;
	
    //tag.csvから入力されたタグと一致したidをとりだし,idに入れる
	while(limit < 100 && fgets(buf,sizeof(buf) + 1,fp_tag) != NULL){
		
		fscanf(fp_tag, "%d, %d, %d, %d, %d", &g.id, &g.shot_time, &g.latitude, &g.longitude, &g.url);
		
		if(strcmp(&id, argv) == 0){
			
			g.id = &id;
			id[limit]= g.id;
			limit++;
		}
	}	
     //geotag.csvの最初からidと一致するidを探し,その行をansに入れる
		FILE *fp_geotag;
		char* geotag_filename = "geotag.csv";
		fp_geotag = fopen(geotag_filename,"r");
		char **ans;

		if(fp_geotag == NULL){
		printf("file open error \n");
		return -1;
		}
		
		for(int i=0; fgets(buf, sizeof(buf)+1, fp_geotag) !=NULL; i++){
		
			for(int i=0; i<100;i++){
			fscanf(fp_geotag, "%d, %d, %d, %d, %d", &g.id, &g.shot_time, &g.latitude, &g.longitude, &g.url);
			
			if(strcmp(id[i],buf) == 0){
					ans[i][0]=buf[0];
					ans[i][1]=buf[1];
					ans[i][2]=buf[2];
					ans[i][3]=buf[3];
					ans[i][4]=buf[4];
			}
			break;
		 }	
		}
		
	free(buf);
	
	for(int i=0; i<100;i++){
		
		for(int j=0; j<5 ;j++){
		
		printf("%d\n", ans[i][j]);
		}
	}

	
	return 0;
}
anonymous No title
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*geotag.csvファイルのIDを探索する関数*/
int geotag_search(FILE* fp, long search_id){
    int ret;
    size_t len = 0;
    int read;
    long result_id; //検索結果のID
    char* time = (char*)malloc(sizeof(char) * 30);      //撮影時刻のID
    double latitute;    //緯度
    double longitute;   //経度
    char* url = (char*)malloc(sizeof(char) * 200);      //URL
    char* geotag_csv_line = (char*)malloc(sizeof(char) * 300); //geotag.csvの一行分の文字列

    if(fp == NULL) {
      return -1;
    }
    /*search_idと同じIDがファイル内に見つかるまで探索*/
    while((read = getline(&geotag_csv_line, &len,fp)) != -1) {
        ret = sscanf(geotag_csv_line, "%ld,%[^,],%lf,%lf,%s", &result_id, time,
		     &latitute, &longitute, url);
        if (result_id == search_id) {
	  //結果を出力
	  printf("%s %lf %lf %s\n", time, latitute, longitute, url);
	  free(time);
	  free(url);
	  free(geotag_csv_line);
	  return read;
	}
    }
    free(time);
    free(url);
    free(geotag_csv_line);
    return read;
}

/*tag.csvファイルのタグを探索する関数*/
void tag_search(FILE* fp,char* search_tag){

  if(fp == NULL) {
    return;
  }

  int ret;
  size_t len = 0;
  int read;
  long id; //tag.csvのID
  char* tag = (char*)malloc(sizeof(char) * 300); //tag.csvのタグ
  char* tag_csv_line = (char*)malloc(sizeof(char) * 320); //tag.csvの一行分の文字列
  FILE* geotag_fp = fopen("../data/geotag.csv","r");
  
  while ((read = getline(&tag_csv_line, &len, fp)) != -1) {
    ret = sscanf(tag_csv_line, "%ld,%[^,]", &id, tag);
    //tag.csvのタグは最後に余計な位置文字(改行?)があるように思われるので
    //それを除いて比較する
    if ((strncmp(tag, search_tag, strlen(search_tag)) == 0)
	&& (strlen(search_tag) == strlen(tag)-1)) {
      if (geotag_fp == NULL) {
	break;
      }
      int g_search = geotag_search(geotag_fp, id);
      if(g_search == -1) {
	return;
      }
    }
  }
  free(tag);
  free(tag_csv_line);
}  

int main(int args,char** argv){
    FILE *fp;

    /*引数にタグがなかった場合のエラー処理*/
    if (args == 1) {
      return 0;
    }
    
    /*ファイルオープンのエラー処理*/
    fp = fopen("../data/tag.csv","r");
    if(fp == NULL) {
      printf("couldn't open file!\n");
      return -1;
    }
    
    tag_search(fp, argv[1]);
    fclose(fp);   
    return 0;
}
anonymous No title
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void search(FILE* fp,char* source_tag);
int geosearch(FILE* fp,char* source_id);
int bool = 1;
int main(int argc,char** argv){
    FILE *fp;
    fp = fopen("../data/tag.csv","r");
    if(fp==NULL){
        printf("file can't open\n");
        return -1;
    }
    /*if(args == 1){
	search(fp,"dog");
	fclose(fp);
	return 0;
}*/
    search(fp,argv[1]);
    // printf("poyo\n");
    fclose(fp);   
    return 0;
}
void search(FILE* fp,char* source_tag){
    if(fp==NULL){
		printf("serch error\n");
		return;
	}
    int read,ret;
    char* id = (char *)malloc(10000);
    char* csv_tag = (char *)malloc(10000);
    int leng = 0;
    char* csv_line = (char*)malloc(20000);
    FILE* geotag = fopen("../data/geotag.csv","r");
    //int count = 0;
    while ((read = getline(&csv_line,&leng,fp))!=-1){
        /* code */
        ret = sscanf(csv_line,"%[^,],%s",id,csv_tag);
        if(strcmp(source_tag,csv_tag)==0){
            if(geotag==NULL)break;
            int gs = geosearch(geotag,id);
            printf("gs:%d\n",gs);
            //count++;
            if(gs==-1){
                printf("geosearch\n");
                fclose(geotag);
                //printf("%d\n",count);
                return;
            } 
        }
        //printf("%d\n",read);
    }
    printf("tag not found\n");
    //printf("%d\n",count);
    fclose(geotag);
    // printf("poyomu\n");
}

int geosearch(FILE* fp,char* source_id){
    int ret,leng;
    char result_id[100],time[1000],url[1000];
    char* csv_line = (char*)malloc(10000);
    
    double latitute,longitute;
    if(fp==NULL)return -1;
    int read;// = getline(&csv_line,&leng,fp);
    while((read = getline(&csv_line,&leng,fp))!=-1){
        ret = sscanf(csv_line,"%[^,],\"%[^\"]\",%lf,%lf,%s",result_id,time,&latitute,&longitute,url);
        strncpy(result_id,csv_line,9);
        //printf("%s\n",csv_line);
        if(strcmp(result_id,source_id)==0){
            // if(read > 1000)return;
            printf("%s,%lf,%lf,%s\n",time,latitute,longitute,url);
            printf("read:%d\n",read);
            return read;
        }
    }
    printf("error\n");
    return 0;
}
anonymous No title
C
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct image{
    char magic[3];
    int width;
    int height;
    int max;
    int image[500][500];
};

struct pattern{ // 領域(パターン)特徴格納用データ構造
    int feature;
    int cluster_number; // クラスタ番号
}p[20];

struct cluster{ // クラスタ属性値格納用データ構造
    int center;
    int prev_center;
    int pattern; // パターン数
    int area_total;
}c[10];

struct image entity;

void read(char infile[20], FILE *infp){
    infp = fopen(infile,"r");

    //Read data from file to each variable
    fscanf(infp, "%s", entity.magic);
    fscanf(infp, "%d", &entity.width);
    fscanf(infp, "%d", &entity.height);
    fscanf(infp, "%d", &entity.max);
    for(int i = 0; i<entity.height; i++){
        for(int j = 0; j<entity.width; j++){
            fscanf(infp, "%d", &entity.image[i][j]);
        }
    }
    fclose(infp);
}

void binarization(){
    int k, kmax, N, n[500];
    double p[500], omega, my, myT, dbc, dbcmax, den;
    
    N = entity.height*entity.width;
    for( k=0; k <= entity.max; k++){
        n[k] = 0;
    }
    for( int i = 0; i<entity.height; i++){
        for( int j = 0; j<entity.width; j++){
            n[entity.image[i][j]]++;
        }
    }
    for( k=0; k <= entity.max; k++){
        p[k] = (double)n[k]/N;
        myT += k*p[k]; 
    }

    double omega0, my0;
    for(k = 0; k<entity.max; k++){
        omega = omega0 + p[k];
        my = my0 + k*p[k];
        den = omega*(1-omega); //denominator
        if(den != 0){
            dbc = (myT*omega-my)*(myT*omega-my)/den; //distributed between classes
            if(dbc > dbcmax){
                kmax = k;
                dbcmax = dbc;
            }
        }
        omega0 = omega;
        my0 = my; 
    }
    for( int i = 0; i<entity.height; i++){
        for( int j = 0; j<entity.width; j++){
            if(entity.image[i][j] > kmax) entity.image[i][j] = entity.max;
            else                          entity.image[i][j] = 0;
        }
    }
    printf("閾値: %d\n", kmax);
}

void set_label(int i, int j, int label){
    entity.image[i][j] = label;
    if(entity.image[i-1][j-1]==entity.max) set_label(i-1, j-1, label);
    if(entity.image[i-1][j]  ==entity.max) set_label(i-1, j,   label);
    if(entity.image[i-1][j+1]==entity.max) set_label(i-1, j+1, label);
    if(entity.image[i][j-1]  ==entity.max) set_label(i,   j-1, label);
    if(entity.image[i][j+1]  ==entity.max) set_label(i,   j+1, label);
    if(entity.image[i+1][j-1]==entity.max) set_label(i+1, j-1, label);
    if(entity.image[i+1][j]  ==entity.max) set_label(i+1, j,   label);
    if(entity.image[i+1][j+1]==entity.max) set_label(i+1, j+1, label);
}

int labeling(){
    int label;
    label = 1;
    for (int i=0; i<entity.height; i++){
        for(int j=0; j<entity.width; j++){
            if(entity.image[i][j]==entity.max){
                set_label(i, j, label);
                label++;
            }
        }
    }
    printf("label: %d\n", label);
    return label;
}

void clustering(int label){
    int cluster=4; // クラスタ数
    int gap_total;
    //printf("cluster: ");
    //scanf("%d", &cluster);
    printf("hogehoge\n");

    for(int y=0; y<entity.height; y++){
        for(int x=0; x<entity.width; x++){
            p[entity.image[y][x]].feature++;
        }
    }
    for(int i=0; i<cluster; i++) c[i].center = p[i].feature;
    do{
        gap_total = 0;
        for(int i=0; i < label; i++){
            int minD = INT_MAX;
            int d;
            for(int j=0; j<cluster; j++){
                d = abs(c[j].center - p[i].feature);
                if(d<minD){
                    minD = d;
                    p[i].cluster_number = j;
                    printf("j: %d  ",j);
                }
            }
        }
        for(int i=0; i < label; i++){
            c[p[i].cluster_number].pattern++;
            c[p[i].cluster_number].area_total += c[i].area_total;
        }
        // c->pattern = pattern_total;
        // c->area_total = area_total;
            printf("hugahuga\n");
    //printf("%d\n", cluster);

        for(int i=0; i<cluster; i++){
    //printf("%d\n %d\n", c[i].center, c[i].pattern);
            //printf("kozukozu\n");
            c[i].prev_center = c[i].center;
            if(c[i].pattern!=0) c[i].center = c[i].prev_center/c[i].pattern;
            gap_total += abs(c[i].center - c[i].prev_center);
        }
    printf("%d\n", cluster);

    }while( gap_total > 0);
}

void write(char outfile[20], FILE *outfp){
    outfp = fopen(outfile,"w");

    //Write data from each variable to a file
    fprintf(outfp, "%s", entity.magic);
    fprintf(outfp, "\n");
    fprintf(outfp, "%d", entity.width);
    fprintf(outfp, " ");
    fprintf(outfp, "%d", entity.height);
    fprintf(outfp, "\n");
    fprintf(outfp, "%d", entity.max);
    fprintf(outfp, "\n");
    for(int i = 0; i<entity.height; i++){
        for(int j = 0; j<entity.width; j++){
            fprintf(outfp, "%d", entity.image[i][j]);
            fprintf(outfp, " ");
        }
    }
    fclose(outfp);
}

int main(int argc, char* argv[]){
    FILE *infp,*outfp; //file pointer
    read(argv[1], infp);
    binarization();
    int label = labeling();
    clustering(label);
    for(int i=0; i<label; i++){
        printf("%d   ", i);
        printf("%d   ", p[i].feature);
        printf("%d\n",p[i].cluster_number);
    }
    write(argv[2], outfp);

    return 0;
}
anonymous No title
C
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct image{
    char magic[3];
    int width;
    int height;
    int max;
    int image[500][500];
};

struct pattern{ // 領域(パターン)特徴格納用データ構造
    int feature;
    int cluster_number; // クラスタ番号
}p[20];

struct cluster{ // クラスタ属性値格納用データ構造
    int center;
    int prev_center;
    int pattern; // パターン数
    int area_total;
}c[10];

struct image entity;

void read(char infile[20], FILE *infp){
    infp = fopen(infile,"r");

    //Read data from file to each variable
    fscanf(infp, "%s", entity.magic);
    fscanf(infp, "%d", &entity.width);
    fscanf(infp, "%d", &entity.height);
    fscanf(infp, "%d", &entity.max);
    for(int i = 0; i<entity.height; i++){
        for(int j = 0; j<entity.width; j++){
            fscanf(infp, "%d", &entity.image[i][j]);
        }
    }
    fclose(infp);
}

void set_label(int i, int j, int label){
    entity.image[i][j] = label;
    if(entity.image[i-1][j-1]==entity.max) set_label(i-1, j-1, label);
    if(entity.image[i-1][j]  ==entity.max) set_label(i-1, j,   label);
    if(entity.image[i-1][j+1]==entity.max) set_label(i-1, j+1, label);
    if(entity.image[i][j-1]  ==entity.max) set_label(i,   j-1, label);
    if(entity.image[i][j+1]  ==entity.max) set_label(i,   j+1, label);
    if(entity.image[i+1][j-1]==entity.max) set_label(i+1, j-1, label);
    if(entity.image[i+1][j]  ==entity.max) set_label(i+1, j,   label);
    if(entity.image[i+1][j+1]==entity.max) set_label(i+1, j+1, label);
}

int labeling(){
    int label=1;
    for (int i=0; i<entity.height; i++){
        for(int j=0; j<entity.width; j++){
            if(entity.image[i][j]==entity.max){
                set_label(i, j, label);
                label++;
            }
        }
    }
    return label;
}

void clustering(int label){
    int cluster; // クラスタ数
    int gap_total;
    printf("cluster: ");
    scanf("%d", &cluster);
    printf("%d", cluster);

    for(int y=0; y<entity.height; y++){
        for(int x=0; x<entity.width; x++){
            p[entity.image[y][x]].feature++;
        }
    }
    for(int i=0; i<cluster; i++) c[i].center = p[i].feature;
    do{
        gap_total = 0;
        for(int i=0; i < label; i++){
            int minD = INT_MAX;
            int d;
            for(int j=0; j<cluster; j++){
                d = abs(c[j].center - p[i].feature);
                if(d<minD){
                    minD = d;
                    p[i].cluster_number = j;
                }
            }
        }
        for(int i=0; i < label; i++){
            c[p[i].cluster_number].pattern++;
            c[p[i].cluster_number].area_total += c[i].area_total;
        }
        // c->pattern = pattern_total;
        // c->area_total = area_total;

        for(int i=0; i<cluster; i++){
            printf("%d", c[i].prev_center);
            c[i].prev_center = c[i].center;
            c[i].center = c[i].prev_center/c[i].pattern;
            gap_total += abs(c[i].center - c[i].prev_center);
        }

    }while( gap_total > 0);
}

void write(char outfile[20], FILE *outfp){
    outfp = fopen(outfile,"w");

    //Write data from each variable to a file
    fprintf(outfp, "%s", entity.magic);
    fprintf(outfp, "\n");
    fprintf(outfp, "%d", entity.width);
    fprintf(outfp, " ");
    fprintf(outfp, "%d", entity.height);
    fprintf(outfp, "\n");
    fprintf(outfp, "%d", entity.max);
    fprintf(outfp, "\n");
    for(int i = 0; i<entity.height; i++){
        for(int j = 0; j<entity.width; j++){
            fprintf(outfp, "%d", entity.image[i][j]);
            fprintf(outfp, " ");
        }
    }
    fclose(outfp);
}

int main(int argc, char* argv[]){
    FILE *infp,*outfp; //file pointer
    read(argv[1], infp);
    int label = labeling();
    clustering(label);
    for(int i=0; i<label; i++){
        printf("%d   ", i);
        printf("%d   ", p[i].feature);
        printf("%d\n",p[i].cluster_number);
    }
    write(argv[2], outfp);

    return 0;
}
anonymous No title
C
void clustering(int label){
    int cluster; // クラスタ数
    int gap_total;
    printf("cluster: ");
    scanf("%d", &cluster);
    
    printf("");

    for(int y=0; y<entity.height; y++){
        for(int x=0; x<entity.width; x++){
            p[entity.image[y][x]].feature++;
        }
    }
    for(int i=0; i<cluster; i++) c[i].center = p[i].feature;
    do{
        gap_total = 0;
        for(int i=0; i < label; i++){
            int minD = INT_MAX;
            int d;
            for(int j=0; j<cluster; j++){
                d = abs(c[j].center - p[i].feature);
                if(d<minD){
                    minD = d;
                    p[i].cluster_number = j;
                }
            }
        }
        for(int i=0; i < label; i++){
            c[p[i].cluster_number].pattern++;
            c[p[i].cluster_number].area_total += c[i].area_total;
        }
        // c->pattern = pattern_total;
        // c->area_total = area_total;

        for(int i=0; i<cluster; i++){
            printf("%d", c[i].prev_center);
            c[i].prev_center = c[i].center;
            c[i].center = c[i].prev_center/c[i].pattern;
            gap_total += abs(c[i].center - c[i].prev_center);
        }

    }while( gap_total > 0);
}
anonymous No title
C
#include<stdio.h>

#define PROF_NUM (2) // 人物情報の総数

int main(void) {
    typedef struct {
        char name[1024]; // 名前
        int age;// 年齢
        double weight; // 体重kg
        double height; // 身長cm
        double BMI; // BMI
    }stProfile; // 構造体の定義と別名の定義
    // 構造体の宣言と初期化
    stProfile profList[PROF_NUM];

    for (int i = 0; i < PROF_NUM; i++) {
        // ①構造体配列profListの各メンバ(.BMI以外)の入力をここに書く

        scanf_s("%1023s", profList[i].name, 1024);
        scanf_s("%d", &profList[i].age);
        scanf_s("%lf", &profList[i].weight);
        scanf_s("%lf", &profList[i].height);

        // BMIの計算 = 体重kg / (身長m * 身長m)
        profList[i].BMI = profList[i].weight / (profList[i].height * profList[i].height);
    }

    printf("\n人物情報一覧\n");

    for (int i = 0; i < PROF_NUM; i++) {
        // ②構造体配列profListの各メンバの出力をここに書く

        printf("名前は%s\n", profList[i].name);
        printf("年齢は%d\n", profList[i].age);
        printf("身長は%.1f\n", profList[i].height);
        printf("体重は%.1f\n", profList[i].weight);
        printf("BMIは%.2f\n", profList[i].BMI);
        printf("\n", profList[i].BMI);

    }
    return 0;
}
anonymous No title
C
#include<stdio.h>

#define PROF_NUM (2) // 人物情報の総数

int main(void) {
    typedef struct {
        char name[1024]; // 名前
        int age;// 年齢
        double weight; // 体重kg
        double height; // 身長cm
        double BMI; // BMI
    }stProfile; // 構造体の定義と別名の定義
    // 構造体の宣言と初期化
    stProfile profList[PROF_NUM];

    for (int i = 0; i < PROF_NUM; i++) {
        // ①構造体配列profListの各メンバ(.BMI以外)の入力をここに書く

        printf("名前、年齢、体重、身長を入力");
        scanf_s("%s", profList[i].name,20);
        scanf_s("%d", &profList[i].age);
        scanf_s("%f", &profList[i].weight);
        scanf_s("%f", &profList[i].height);

        // BMIの計算 = 体重kg / (身長m * 身長m)
        profList[i].BMI = profList[i].weight / (profList[i].height * profList[i].height * 1.0e-4);
    }

    printf("\n人物情報一覧\n");

    for (int i = 0; i < PROF_NUM; i++) {
        // ②構造体配列profListの各メンバの出力をここに書く
       
        printf("%f", &profList[i].BMI);

    }
    return 0;
}
Don't you submit code?
Submit