#include <stdio.h> #include <math.h> #include <assert.h> #include <string.h> void square() { #define eps 1e-8 int n; double a1,a2; scanf("%d",&n); printf("-----------------------------/n"); assert(n >= 0); a1 = 1.0; a2 = 2.0; while (fabs(a1-a2) > eps) { a2 = (a1 + n/a1)/2; a1 = (a2 + n/a2)/2; printf("a1= %f, a2 = %f/n",a1,a2); } #undef eps } void printprime(void) { #define N 100 int count; int iCnt; int jCnt; printf(" 2 3 "); count = 2; for (iCnt = 5; iCnt < 100; iCnt += 2) { for (jCnt = 3;jCnt * jCnt < iCnt; jCnt += 2) if (iCnt % jCnt == 0) break; if (jCnt * jCnt > iCnt) { if (count % 10 == 0) printf("/n"); printf("%2d ",iCnt); count++; } } printf("/n"); } void Triangle(void) { int a,b,c; int max; scanf("%d %d %d",&a,&b,&c); printf("---------/n"); printf("a = %d,b = %d,c = %d/n",a,b,c); bool flag1,flag2; max = (a > b) ? a:((b>c)?b:c); if (a+b+c <= 2*max) { printf("is not a triangle"); return; } flag1 = (a == b); flag2 = (b == c); if (flag1 && flag2) printf("等边三角形/n"); else if (flag1 || flag2) printf("等腰三角形/n"); else printf("一般三角形/n"); } void copy_n(char dst[], char src[],int n) { int index; assert(dst != NULL&& src != NULL); for (index = 0; index < n && src[index]; ++index) dst[index] = src[index]; if (index < n-1) { for (; index < n; ++index) dst[index] = 0; } } void printfText(void) { #define MAXLEN 128 char first[MAXLEN],last[MAXLEN],str[MAXLEN]; FILE *stream; memset(first,0,sizeof(first)); memset(last,0,sizeof(last)); memset(str,0,sizeof(str)); stream = fopen("1.txt","w+"); if (stream == NULL) { printf("创建失败/n"); return; } while (gets(str)) { strcpy(first,str); if (strcmp(first,last) == 0) { fseek(stream,0L,SEEK_CUR); fwrite(last,sizeof(char),strlen(last),stream); fwrite("/n",sizeof(char),1,stream); while(gets(str)) { strcpy(first,str); if (strcmp(first,last) != 0x00) break; } } strcpy(last,first); } fclose(stream); #undef MAXLEN } int substr(char dst[],char src[],int start, int len) { size_t srclen; int index; srclen = strlen(src); if ((len > srclen) || start < 0 || len < 0) { dst[0] = 0; return 0; } for (index = 0; index < len && src[start+index]; ++index) dst[index] = src[index+start]; dst[index] = 0; return index; } void deblank(char str[]) { size_t lenstr,index,jindex; lenstr = strlen(str); for (index = 0,jindex = 0; index <= lenstr; ) { if (str[index] != ' ') str[jindex++] = str[index++]; else { str[jindex++] = str[index++]; while (index < lenstr && str[index] == ' ') { index++; } } } } int main() { printfText(); return 0; }