C section 1.1 b

http://a280606790.iteye.com/blog/770314

vim command 

/*ID:Xiao
LANG:C
TASK:ride
*/
#include<stdio.h>
#define M 6
int main(){
        int i;
        char one[M];
        char two[M];
        long temp1=1;
        long temp2=1;
        FILE *fin=fopen("ride.in","r");
        FILE *fout=fopen("ride.out","w");
        fscanf(fin,"%s",& *one);
        fscanf(fin,"%s",& *two);
        for(i=0;i<M;i++){
                if (one[i]!=NULL)
                temp1*=(one[i]-64);
                else
                continue;
                if (two[i]!=NULL)
                temp2*=(two[i]-64);
                else
                break;
        }
  if(temp1%47==temp2%47)
                fprintf(fout,"%s\n","GO");
        else
                fprintf(fout,"%s\n","STAY");
        return 0;

}

example;

#include <stdio.h>
#include <ctype.h>
int hash(char *s)
{
        int i, h;
        h = 1;
        for(i=0; s[i] && isalpha(s[i]); i++)
                h = ((s[i]-'A'+1)*h) % 47;
        return h;
}
void main(void)
{
        FILE *in, *out;
        char comet[100], group[100];  /* bigger than necessary, room for newline */
        in = fopen("input.txt", "r");
        out = fopen("output.txt", "w");
        fgets(comet, sizeof comet, in);
        fgets(group, sizeof group, in);
        if(hash(comet) == hash(group))
                fprintf(out, "GO\n");
        else
                fprintf(out, "STAY\n");
        exit (0);
}


//after 23 submits this one finally works. 

//char array and char string  http://www.quanxue.cn/JC_CLanguage/CLang/Clang10.html

// the input and output file opening

// the byte of the number is not enough(maybe)

//http://stackoverflow.com/questions/7271939/declared-with-attribute-warn-unused-result  

 warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result



發佈了22 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章