示例#1
0
inline int readLine(int * a, int * b)
{
    *a = 0;
    *b = 0;
    int tmp = getchar_unlocked();
    if (tmp == EOF) return -1;
    while (tmp != ' ')
    {
         *a = *a*10 + (tmp-48);
         tmp = getchar_unlocked();
    }
    tmp = getchar_unlocked();
    while (tmp != '\n')
    {
         *b = *b*10 + (tmp-48);
         tmp = getchar_unlocked();
    }
    return 0;
}
示例#2
0
inline void fastRead_int(int &x) {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;

    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

    if(c=='-') {
     neg = 1;
     c = getchar_unlocked();
    }

    for(; c>47 && c<58 ; c = getchar_unlocked()) {
     x = (x<<1) + (x<<3) + c - 48;
    }

    if(neg)
     x = -x;
}
示例#3
0
inline int gint()
{
    int n = 0;
    int sign=1;
    register char c=0;
    while(c<33)
        c=getchar_unlocked();
    if (c=='-')
    {
        sign=-1;
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        n=(n<<3)+(n<<1)+(c-'0');
        c=getchar_unlocked();
    }
return n*sign;
}
示例#4
0
int fast_int()
{
        int n = 0;
    int negflag=0;
        char c = getchar_unlocked();
    if(c=='-')
        negflag=1;
        while (!('0' <= c && c <= '9'))
        {
                c = getchar_unlocked();
        }
        while ('0' <= c && c <= '9')
        {
                n = (n<<3)+(n<<1) + c - '0';
                c = getchar_unlocked();
        }
    if(negflag==1)
        n*=-1;
        return n;
}
示例#5
0
文件: candy3.cpp 项目: AlgoStuff/SPOJ
long long input()
{
  long long x=0;
  char c;
  for(;;)
  {
    c=getchar_unlocked();
    if (c=='\n') return x;
    x=10*x+c-'0';
  }
  return x;
}
示例#6
0
int main()
{
    int n,q,a,b,i;
    char c,d;
    n=inp();
    q=inp();
    for(i=0; i<=n; i++) ft[i]=0;
    maxVal=n;
    while(q--)
    {
        c=getchar_unlocked();
        while (c!='a' && c!='f') c=getchar_unlocked();
        d=c;
        while(c!=' ') c=getchar_unlocked();
        a=inp();
        b=inp();
        if(d=='a') update(a,b);
        else printf("%d\n",query_r(a,b));
    }
    return 0;
}
示例#7
0
int main()
{
  fflush(stdin);
  int k=0,inpt[101],outpt[101];
  char c,flag=1; 
  while(flag)
  { int n=0,num=0,i=0,smoke=0;//n=size of input
    while((c=getchar_unlocked())!='\n')
          n=(n<<3)+(n<<1)+(c-'0');
    //taking the array         
    for( i=1;i<=n;i++)
        {
            do
              {
                  c=getchar_unlocked();
                  num=(num<<3)+(num<<1)+(c-'0');
              }while(c!=' '||c!=EOF||c!='\n');
            inpt[i]=num;
            if(c==EOF)flag=0;
        }
      //calculating smoke
      for(i=1;i<n;i++)
       { int p=inpt[1]*inpt[2],a=(inpt[1]+inpt[2])%100,pos=1,j=0,limit=n-i,combined=0,min=0;
         combined=a*p;
         min=combined;
         for(j=2;j<=limit;j++)
           { 
            p=inpt[i]*inpt[i+1],a=(inpt[i+1]+inpt[i])%100;
            combined=a*p;
            if(min>combined){pos=i;min=combined;}
            else if(min==combined){if(a>((inpt[pos]+inpt[pos+1])%100))pos=i; }  
            }
         smoke+=inpt[pos]*inpt[pos+1];inpt[pos]=(inpt[pos]+inpt[pos+1])%100;
         for(j=pos+1;j<limit;j++)inpt[j]=inpt[j+1];
        }
        outpt[k++]=smoke;
     }
      int i=0;
      for(;i<k;i++)printf("%d\n",outpt[i]); 
  }          
int64_t readIntFromBufferAndAdvance()
{
  long long noRead=0;
  int sign=0;
  char p=getchar_unlocked();
  for(;p<33;){p=getchar_unlocked();};
  if(p == '-')
	{
	  sign=1;
	  p=getchar_unlocked();
	}
  for(;p>32;)
	{
	  noRead = noRead * 10 + (p - '0');
	  p=getchar_unlocked();
	}
  if(sign)
	{
	  noRead*=-1;
	}
  return noRead;  
};
示例#9
0
int main(){
long n;

long i;
char s;
double a,f;

int flag=0,*number;
 scanf("%d",&n);
 char x[n];
 inline void fast_read(int *number){
 	*number=0;
 	char currentChar=getchar_unlocked();

 	while(currentChar<'0'||currentChar>'9')
 	currrentChar=getchar_unlocked();

 	while(currentChar>='0'&&currentChar<='9'){
 		*number=(*number)*10+currentChar='0';
		 currentChar=getchar_unlocked();

 	}
 }
示例#10
0
int main()
{
	char c,a;
	int t,n;
	readInt(&t);
	while(t--)
	{
		readInt(&n);
		while((c=getchar_unlocked())>64)
		{
		a=c;
		}
		printf("%c\n",a);
	}
}
示例#11
0
文件: fastexpr.c 项目: nphuc/alg
int main(){
    char s[1000];
    register int i=0;
    int c;
    while((c=getchar_unlocked())!=EOF){
    	if(!isspace(c)){
    		s[i++]=c;
    	}
    }
    s[i]=0;
    stack st;
    prebuild(s,&st);
    stack out;
    //postfix(&st,&out);
    //long res=compute(&out);
    //printf("res1=%ld\n",res);
    long res2=solve(&st);
    printf("%ld",res2);
    return 0;
}
示例#12
0
/*
 * getinput -- read user input from stdin abort on ^C
 *
 *	Entry	noecho == TRUE, don't echo input.
 *
 *	Exit	User's input.
 *		If interrupted, send SIGINT to caller for processing.
 */
static char *
getinput(int noecho)
{
	struct termio tty;
	unsigned short tty_flags = 0;
	char input[PAM_MAX_RESP_SIZE + 1];
	int c;
	int i = 0;
	void (*sig)(int);

	ctl_c = 0;
	sig = signal(SIGINT, interrupt);
	if (noecho) {
		(void) ioctl(fileno(stdin), TCGETA, &tty);
		tty_flags = tty.c_lflag;
		tty.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
		(void) ioctl(fileno(stdin), TCSETAF, &tty);
	}
	/* go to end, but don't overflow PAM_MAX_RESP_SIZE */
	flockfile(stdin);
	while (ctl_c == 0 &&
	    (c = getchar_unlocked()) != '\n' &&
	    c != '\r' &&
	    c != EOF) {
		if (i < PAM_MAX_RESP_SIZE) {
			input[i++] = (char)c;
		}
	}
	funlockfile(stdin);
	input[i] = '\0';
	if (noecho) {
		tty.c_lflag = tty_flags;
		(void) ioctl(fileno(stdin), TCSETAW, &tty);
		(void) fputc('\n', stdout);
	}
	(void) signal(SIGINT, sig);
	if (ctl_c == 1)
		(void) kill(getpid(), SIGINT);

	return (strdup(input));
}
示例#13
0
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int N; scanf("%d\n", &N); 
	for(int i = 0; i < N; i++)
		testo[i] = getchar_unlocked();
	
	bool smt = false;
	
	for(int i = 0; i < N; i++)
	{
		bool cP = 1, cT = 1;
		
		while(cP || cT)
		{
			cP = checkPah(i);
			if(cP)
			{
				i += 3;
				if(smt) { printf(" "); smt = 0; }
			}
			cT = checkTunz(i);
			if(cT)
			{
				i += 4;
				if(smt) { printf(" "); smt = 0; }
			}
		}
		
		smt = true;
		if(i >= N) break;
		printf("%c", testo[i]);
	}
	
	printf("\n");
	
	return 0;
	
}
示例#14
0
文件: candy3.cpp 项目: AlgoStuff/SPOJ
int main()
{
  int T,i,N,j;
  long long sum,c;
  T=input();
  for (i=0; i<T; i++)
  {
    getchar_unlocked();
    N=input();
    sum=0;
    for (j=0; j<N; j++)
    {
      c=input();
      sum=(sum+c%N)%N;
    }
    if (sum)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
示例#15
0
int main(){
	int t, NG, NM, maxG, maxM, tmp;
	fast_scani(&t);
	while(t--){
		getchar_unlocked();
		fast_scani(&NG);
		fast_scani(&NM);
		maxM = maxG = 0;
		while(NG--){
			fast_scani(&tmp);
			if(tmp > maxG) maxG = tmp;
		}
		while(NM--){
			fast_scani(&tmp);
			if(tmp > maxM) maxM = tmp;
		}
		if(maxG >= maxM)
			printf("%s\n", "Godzilla");
		else
			printf("%s\n", "MechaGodzilla");			
	}	return 0;
}
示例#16
0
int main () {
  int n;
  while(scanf("%d",&n)) {
    getchar_unlocked();
    if (n == -1) break;
    gets(s);
    size = strlen(s);
    if (s[size-1] == '\n') --size;

    if (n < size) {
      printf("0\n");
      continue;
    }
    kmp();
    int len = size-arr[size-1];

    //    for (int i = 0; i < size; ++i) { cout<<arr[i]<<endl;}
    n -= size;
    //  printf("size = %d, n = %d\n",size,n);
    printf("%d\n",((n/len)+1));
  }
}
示例#17
0
文件: gets.c 项目: 16rd/rt-n56u
char *gets(char *s)
{
	register char *p = s;
	int c;
	__STDIO_AUTO_THREADLOCK_VAR;

	__STDIO_AUTO_THREADLOCK(stdin);

	/* Note: don't worry about performance here... this shouldn't be used!
	 * Therefore, force actual function call. */
	while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
		++p;
	}
	if ((c == EOF) || (s == p)) {
		s = NULL;
	} else {
		*p = 0;
	}

	__STDIO_AUTO_THREADUNLOCK(stdin);

	return s;
}
示例#18
0
static void
narrow (const char *path)
{
  FILE *old_stdin = stdin;
  stdin = xfopen (path, "r");

  TEST_COMPARE (getchar (), 'a');
  TEST_COMPARE (getchar_unlocked (), 'b');
  char ch = 1;
  TEST_COMPARE (scanf ("%c", &ch), 1);
  TEST_COMPARE (ch, 'c');
  TEST_COMPARE (call_vscanf ("%c", &ch), 1);
  TEST_COMPARE (ch, 'd');
  char buf[8];
  memset (buf, 'X', sizeof (buf));

  /* Legacy interface.  */
  extern char *gets (char *);
  TEST_VERIFY (gets (buf) == buf);
  TEST_COMPARE_BLOB (buf, sizeof (buf), "ef\0XXXXX", sizeof (buf));

  fclose (stdin);
  stdin = old_stdin;
}
示例#19
0
int main()
{
    int t,i,j,count[2][5]={0};
    int ls=0,lf=0,temp,k,l;
    t=scan();
    char a[20010];
    char b[20010];
    for(i=0;i<t;i++)
    {
        for(k=0;k<2;k++)
        {
            for(l=0;l<5;l++)
            {
                count[k][l]=0;
            }
        }
        ls=0;lf=0;
        char c;
        j=0;
        c=getchar_unlocked();
        while(c!='\n')
        {
            a[j++]=c;
            c=getchar_unlocked();
        }
        a[j]='\0';
        j=0;
        c=getchar_unlocked();
        while(c!='\n')
        {
            b[j++]=c;
            c=getchar_unlocked();
        }
        b[j]='\0';
        //printf("%c",a[0]);
        for(j=0;j<strlen(a);j++)
        {
            if(a[j]>'7')
                count[0][0]++;
            else if(a[j]=='7')
                count[0][1]++;
            else if(a[j]<'7' && a[j]>'4')
                count[0][2]++;
            else if(a[j]=='4')
                count[0][3]++;
            else if(a[j]<'4' && a[j]>='0')
                count[0][4]++;

            if(b[j]>'7')
                count[1][0]++;
            else if(b[j]=='7')
                count[1][1]++;
            else if(b[j]<'7' && b[j]>'4')
                count[1][2]++;
            else if(b[j]=='4')
                count[1][3]++;
            else if(b[j]<'4' && b[j]>='0')
                count[1][4]++;

        }

        //-----------------------------
        int p1[5]={0,2,4,3,1};
        for(j=0;j<5;j++)
        {
            if(count[0][0]<=count[1][p1[j]])
            {
                temp=count[0][0];
                count[0][0]=0;
                count[1][p1[j]]-=temp;
                break;
            }
            else
            {
                temp=count[1][p1[j]];
                count[1][p1[j]]=0;
                count[0][0]-=temp;
            }
        }
        for(j=0;j<5;j++)
        {
            if(count[1][0]<=count[0][p1[j]])
            {
                temp=count[1][0];
                count[1][0]=0;
                count[0][p1[j]]-=temp;
                break;
            }
            else
            {
                temp=count[0][p1[j]];
                count[0][p1[j]]=0;
                count[1][0]-=temp;
            }
        }

        //-----------------------------

        int p2[4]={2,4,3,1};
        for(j=0;j<4;j++)
        {
            if(count[0][1]<=count[1][p2[j]])
            {
                temp=count[0][1];
                count[0][1]=0;
                count[1][p2[j]]-=temp;
                ls+=temp;
                break;
            }
            else
            {
                temp=count[1][p2[j]];
                count[1][p2[j]]=0;
                count[0][1]-=temp;
                ls+=temp;
            }
        }
        for(j=0;j<4;j++)
        {
            if(count[1][1]<=count[0][p2[j]])
            {
                temp=count[1][1];
                count[1][1]=0;
                count[0][p2[j]]-=temp;
                ls+=temp;
                break;
            }
            else
            {
                temp=count[0][p2[j]];
                count[0][p2[j]]=0;
                count[1][1]-=temp;
                ls+=temp;
            }
        }

        //-------------------------------

        int p3[3]={2,4,3};
        for(j=0;j<3;j++)
        {
            if(count[0][2]<=count[1][p3[j]])
            {
                temp=count[0][2];
                count[0][2]=0;
                count[1][p3[j]]-=temp;

                break;
            }
            else
            {
                temp=count[1][p3[j]];
                count[1][p3[j]]=0;
                count[0][2]-=temp;

            }
        }
        for(j=0;j<4;j++)
        {
            if(count[1][2]<=count[0][p3[j]])
            {
                temp=count[1][2];
                count[1][2]=0;
                count[0][p3[j]]-=temp;

                break;
            }
            else
            {
                temp=count[0][p3[j]];
                count[0][p3[j]]=0;
                count[1][2]-=temp;

            }
        }

        //-------------------------------
        int p4[2]={4,3};
        for(j=0;j<2;j++)
        {
            if(count[0][3]<=count[1][p4[j]])
            {
                temp=count[0][3];
                count[0][3]=0;
                count[1][p4[j]]-=temp;
                lf+=temp;
                break;
            }
            else
            {
                temp=count[1][p4[j]];
                count[1][p4[j]]=0;
                count[0][3]-=temp;
                lf+=temp;
            }
        }
        for(j=0;j<2;j++)
        {
            if(count[1][3]<=count[0][p4[j]])
            {
                temp=count[1][3];
                count[1][3]=0;
                count[0][p4[j]]-=temp;
                lf+=temp;
                break;
            }
            else
            {
                temp=count[0][p4[j]];
                count[0][p4[j]]=0;
                count[1][3]-=temp;
                lf+=temp;
            }
        }

        //-------------------------------

        for(j=0;j<ls;j++)
            putchar('7');
        for(j=0;j<lf;j++)
            putchar('4');

        putchar('\n');
    }
    return 0;
}
示例#20
0
int main() {
	struct suffix suffixes[1005];
	char A[1005];
	int pos[1005],lcp[1005],nw[1005];
	int *group, *group_bool;
	int start,end,min,global_max,global_index;
	int nwords=1,max_words;
	char c;
	int i=0,len=0;
	int j=0,k=0;
	int sum=0;
	nwords=1;
	c=getchar_unlocked();
	while(c!='\n') {
		suffixes[i].size=i+1;
		if(c=='$') nwords++;
		A[i]=c;
		c=getchar_unlocked();
		i++;
	}
	max_words=nwords;
	suffixes[i].size=i+1;
	A[i]='$';
	strcpy(suffixes[i].ar,A); 
	len=i; 
	nwords=1;
	for(j=0;j<=len;j++) {
		for(k=j;k<=len;k++) {
			suffixes[i].ar[k-j]=A[k];
			suffixes[i].nwords=max_words+1-nwords;
		}
		if(suffixes[i].ar[0]=='$') nwords++;
		i--;
	}
	
	qsort(suffixes,len+1,sizeof(struct suffix),cmp);

	for(i=0;i<=len;i++) {
		pos[i]=len+1-suffixes[i].size;
		nw[i]=suffixes[i].nwords;
	}

	group=(int *)malloc((max_words+1)*sizeof(int));
	group_bool=(int *)malloc((max_words+1)*sizeof(int));

	for(i=0;i<=max_words;i++) {
		group[i]=0;
		group_bool[i]=0;
	}
	global_max=0;global_index=0;
	start=max_words;
	end=start;		
	while(start<=len && end<=len) {
		sum=0;
		for(i=1;i<=max_words;i++) {
			sum+=group_bool[i];
		}
		while(sum!=max_words) {
			if(group_bool[nw[end]]==0) {
				group_bool[nw[end]]=1;
				sum++;
			}
			group[nw[end]]++;
			end++;
		}	
		end--;
		min=lcp_two(&suffixes[start],&suffixes[end]);
		if(min>global_max) {
			global_max=min;
			global_index=start;
		}
		while(sum==max_words) {
			group[nw[start]]--;
			if(group[nw[start]]==0) {
				group_bool[nw[start]]=0;
				sum--;
			}
			start++;
			if(sum==max_words) {
				min=lcp_two(&suffixes[start],&suffixes[end]);
				if(min>global_max) {
					global_max=min;
					global_index=start;
				}
			}
		}
		end++;
	}	
	printf("The longest common substring (not unique)\n");
	for(i=0;i<global_max;i++) {
		printf("%c",suffixes[global_index].ar[i]);
	}
	printf("\n");
	return 0;
}
示例#21
0
文件: lining.cpp 项目: M4573R/pc-code
 void read() { b = getchar_unlocked(); }
示例#22
0
int Read(int ind) { char ch=0; int a=0; while(ch<33) ch=getchar_unlocked(); while(ch>33) { A[ind][N-3-a++]=ch-'0'; ch=getchar_unlocked(); } A[ind][N-1]=A[ind][N-2]=0; }
示例#23
0
int
main(int argc, char *argv[])
{
	char	buffer[BUFSIZ];
	wchar_t	wbuffer[BUFSIZ];
	char	*buf;
	wchar_t	*wbuf;
	FILE	*f;
	off_t	off;
	fpos_t	pos;
	size_t	size;
	int	fd, r;
	char	c;
	wchar_t	wc;

	if ((fd = dup(1)) == -1)
		err(2, "dup");
	if ((dup_stdout = fdopen(fd, "w")) == NULL)
		err(2, "fdopen");
	if ((fd = mkstemp(filename)) == -1)
		err(2, "mkstemp");
	if (write(fd, "0123456789\n\n", 12) != 12 || close(fd))
		err(2, "write + close");

	/* status */
	TEST_UNCHANGED(fwide(f, 0));
	TEST_NARROW(fwide(f, -1));
	TEST_WIDE(fwide(f, 1));
	TEST_UNCHANGED(feof(f));
	TEST_UNCHANGED(ferror(f));
	TEST_UNCHANGED(fileno(f));
	TEST_UNCHANGED(clearerr(f));

	/* flush and purge */
	TEST_UNCHANGED(fflush(f));
	TEST_UNCHANGED(fpurge(f));

	/* positioning */
	TEST_UNCHANGED(fgetpos(f, &pos));
	TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos));
	TEST_UNCHANGED(ftell(f));
	TEST_UNCHANGED(ftello(f));
	TEST_UNCHANGED(fseek(f, 1, SEEK_CUR));
	TEST_UNCHANGED(fseek(f, 1, SEEK_SET));
	TEST_UNCHANGED(fseek(f, 1, SEEK_END));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_SET));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_END));
	TEST_UNCHANGED(rewind(f));

	/* buffering */
	TEST_UNCHANGED(setbuf(f, NULL));
	TEST_UNCHANGED(setbuf(f, buffer));
	TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0));
	TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0));
	TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0));
	TEST_UNCHANGED(setbuffer(f, NULL, 0));
	TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ));
	TEST_UNCHANGED(setlinebuf(f));

	/* locking */
	TEST_UNCHANGED(flockfile(f);funlockfile(f));
	TEST_UNCHANGED(ftrylockfile(f);funlockfile(f));

	/* input */
	TEST_NARROW(getc(f));
	TEST_NARROW(getc_unlocked(f));
	TEST_NARROW(fgetc(f));
	TEST_NARROW(c = fgetc(f); ungetc(c, f));
	TEST_NARROW(fgets(buffer, BUFSIZ, f));
	TEST_NARROW(fscanf(f, "%s\n", buffer));
	TEST_NARROW(fgetln(f, &size));

	/* output */
	TEST_NARROW(putc('c', f));
	TEST_NARROW(putc_unlocked('c', f));
	TEST_NARROW(fputc('c', f));
	TEST_NARROW(fputs("foo", f));
	TEST_NARROW(fprintf(f, "%s\n", "foo"));

	/* input from stdin */
	TEST_NARROW_STD(stdin, getchar());
	TEST_NARROW_STD(stdin, getchar_unlocked());
	TEST_NARROW_STD(stdin, fgets(buffer, BUFSIZ, stdin));
	TEST_NARROW_STD(stdin, scanf("%s\n", buffer));

	/* output to stdout */
	TEST_NARROW_STD(stdout, putchar('c'));
	TEST_NARROW_STD(stdout, putchar_unlocked('c'));
	TEST_NARROW_STD(stdout, puts("foo"));
	TEST_NARROW_STD(stdout, printf("foo"));

	/* word-size ops */
	/*
	 * fread and fwrite are specified as being implemented in
	 * terms of fgetc() and fputc() and therefore must set the
	 * stream orientation to narrow.
	 */
	TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f));
	TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f));

	/*
	 * getw() and putw() aren't specified anywhere but logically
	 * should behave the same as fread/fwrite.  Not all OSes agree:
	 * Solaris 10 has them not changing the orientation.
	 */
	TEST_NARROW(getw(f));
	TEST_NARROW(putw(1234, f));


	/* WIDE CHAR TIME! */

	/* input */
	TEST_WIDE(getwc(f));
	TEST_WIDE(fgetwc(f));
	TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f));
	TEST_WIDE(fgetws(wbuffer, BUFSIZ, f));
	TEST_WIDE(fwscanf(f, L"%s\n", wbuffer));

	/* output */
	TEST_WIDE(putwc(L'c', f));
	TEST_WIDE(fputwc(L'c', f));
	TEST_WIDE(fputws(L"foo", f));
	TEST_WIDE(fwprintf(f, L"%s\n", L"foo"));

	/* input from stdin */
	TEST_WIDE_STD(stdin, getwchar());
	TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer));

	/* output to stdout */
	TEST_WIDE_STD(stdout, putwchar(L'c'));
	TEST_WIDE_STD(stdout, wprintf(L"foo"));


	/* memory streams */
	f = open_memstream(&buf, &size);
	if (!((r = fwide(f, 0)) < 0))
		fail(__LINE__, r, "<", "open_memstream()");
	fclose(f);
	f = open_wmemstream(&wbuf, &size);
	if (!((r = fwide(f, 0)) > 0))
		fail(__LINE__, r, ">", "open_wmemstream()");
	fclose(f);


	/* random stuff? */
	TEST_UNCHANGED_STD(stderr, perror("foo"));

	remove(filename);
	if (failures)
		exit(1);
	exit(0);
}
示例#24
0
#include <stdio.h>

 

#define LIMIT 10000

 

#define READ_INT(_x)					
 {							

    int _tmp = 0;					

    register int _ch = getchar_unlocked();		

    while (_ch == '\n' || _ch == ' ')			

      _ch = getchar_unlocked();				

    while (48 <= _ch && _ch <= 57)			

      {							

	_tmp = (_tmp << 3) + (_tmp << 1) + _ch - 48;	

	_ch = getchar_unlocked();			

      }							

    (_x) = _tmp;					
示例#25
0
文件: txt.c 项目: HakanL/UsbIrToy
void IRtxtplay(	char *param_fname,int fd,char *param_delay)
{

#ifndef _WIN32
    bool no_data_yet=TRUE, file_created=FALSE;
#else
    BOOL no_data_yet=TRUE, file_created=FALSE;
#endif
    int res;
    int fcounter;
    char buffer[4*1024] = {0};  //   buffer
    char fnameseq[255];
    FILE *fp=NULL;
    int i;
    file_created=FALSE;
    no_data_yet=TRUE;
    char inkey;
    char temp[4];
    char *token;
    char hex1[2];
    char hex2[2];
    uint8_t buf[4*1024];

    //check filename if exist
    printf(" Entering Player Mode \n");
    fcounter=0;
    inkey=0;
    int delay = atoi(param_delay) ;
    int firstfile = 0;
    while (1)
    {
        sprintf(fnameseq,"%s_%03d.txt",param_fname,fcounter);
        fp=fopen(fnameseq,"rt");
        if (fp==NULL)
        {
            if (fcounter > 0)
                printf(" No more file(s). \n");
            else
                printf(" File does not exits. \n");

            break;
        }
        if (delay< 0)
        {
            printf(" Press a key to start playing %s or X to exit \n",fnameseq);
            while (1)
            {
                if(kbhit())
                {
#ifdef _WIN32
                    inkey=getch();
#else
                    inkey=getchar_unlocked();
                    //	  inkey = fgetc(stdin);
#endif

                    if ((inkey=='x') || (inkey=='X'))
                    {
                        serial_write( fd, "\x00", 1); // JTR
                        break;
                    }
                    else
                        break;

                }

            }
            if (inkey=='x'|| inkey=='X')
            {
                serial_write( fd, "\x00", 1);  // JTR
                break;
            }
        }
        if ((delay > 0) && (firstfile++ > 0))
        {
            printf(" Auto playing %s with %d seconds delay. \n",fnameseq,atoi(param_delay));
#ifdef _WIN32
            Sleep(atoi(param_delay));           //auto play. Do not wait for keyboard input, just wait the specified time (miliseconds)
#else
            sleep(atoi(param_delay));           //auto play. Do not wait for keyboard input, just wait the specified time (miliseconds)
#endif
        }

        printf("\n Playing file: %s\n",fnameseq);

        int comsresult = 0;
        //int bytestx;

        serial_write( fd, "\x03", 1);

        printf(" Sending IRCodes...\n\n");
        int c=0;
        while(!feof(fp))
        {
            for(i=0; i<sizeof(buffer); i++)
                buffer[i]='\0';
            if ((res=fread(&buffer,sizeof(unsigned char),sizeof(buffer),fp)) > 0)
            {

                token = strtok (buffer," ");
                while (token != NULL)
                {
                    strcpy(temp,token);
                    //convert hex string into real hex, by fair
                    sprintf(hex1,"%c%c",temp[0],temp[1]);
                    i = (uint8_t) strtoul(hex1, NULL, 16);
                    buf[c++]=i;
                    sprintf(hex2,"%c%c",temp[2],temp[3]);
                    i = (uint8_t) strtoul(hex2, NULL, 16);
                    buf[c++]=i;

                    if (verbose==TRUE)
                        printf(" %02X%02X",buf[c-2],buf[c-1]);

                    if ( c == 62)
                    {
                        comsresult = serial_write( fd, (char *) buf, c);
                        c = 0;
                    }
                    token = strtok (NULL, " ");
                }
                if (c != 0)
                    comsresult = serial_write( fd, (char *) buf, c);

                c=0;
                printf("\n");
                #ifdef _WIN32
                Sleep(2500);
                #else
                sleep(3);
                #endif
//                comsresult = serial_write( fd, "\x24", 1);
//                res= serial_read(fd, buffer, 3);  //get number of bytes sent
//                if (res >= 3)
//                {
//                    if(buffer[0]=='t')
//                    {
//                        bytestx=(buffer[1]<<8)+(uint8_t)buffer[2];
//                        printf(" IR Toy transmitted: %d bytes\n", bytestx);
//                        //if(bytestx==totalbytes) ok else failed;
//                    }
//                    else
//                    {
//                        printf(" Bad reply:");
//                        for (i=0; i<3; i++)
//                            printf(" %02X ",(uint8_t)buffer[i]);
//                    }
//                    printf("\n");
//
//                    break;
//                }
//                else
//                {
//
//                    printf(" Bad reply:");
//                    for (i=0; i<3; i++)
//                        printf(" %02X ",(uint8_t)buffer[i]);
//                }

                if (delay > 0)
                {
#ifdef _WIN32
                    // temporary disabled to alow to pass here.. in win64 param_delay with -1 seems to wait forever. --Need to confirm
                    Sleep(atoi(param_delay)*1000);           //auto play. Do not wait for keyboard input, just wait the specified time (miliseconds)
#else
                    sleep(atoi(param_delay));           //auto play. Do not wait for keyboard input, just wait the specified time (miliseconds)
#endif
                }
            }
        }
        // serial_write( fd, "\xFF\xFF", 1);

        printf("\n\n");
        printf(" Reached end of file: %s \n",fnameseq);
        fclose(fp);
        fcounter++;
    }

}
示例#26
0
inline void fastread(unsigned int &x){
  register unsigned int c = getchar_unlocked();
  x = 0;
  for(; ((c<48||c>57));c=getchar_unlocked());
  for(;c>47&&c<58;c=getchar_unlocked()) x = (x<<1)+(x<<3)+c-48;
}
示例#27
0
int main()
{
  outBuff=(char *)malloc(sizeof(char)*1005000);
  TempBuf=outBuff;
  numStrings=readIntFromBufferAndAdvance();
  namesArr = (char **)malloc(sizeof(char*) * numStrings);
  int i=0;
  for(i=0;i<numStrings;++i)
	{
	  namesArr[i]=(char *)malloc(sizeof(char) * 1001);
	}
  for(i=0;i<numStrings;++i)
	{
	  char ch;
	  int curLen=0;
	  while((ch=getchar_unlocked())!=' ')
	  	{
	  	  namesArr[i][curLen]=ch;
	  	  ++curLen;
		}
	  namesArr[i][curLen]='\0';
	  level3Arr[i].name=namesArr[i];
	  level3Arr[i].priority=readIntFromBufferAndAdvance();
	}
  numQueries=readIntFromBufferAndAdvance();
  queriesArr = (char **)malloc(sizeof(char*) * numQueries);
  for(i=0;i<numQueries;++i)
	{
	  queriesArr[i]=(char *)malloc(sizeof(char) * 1001);
	}
  for(i=0;i<numQueries;++i)
	{
	  char ch;
	  int curLen=0;
	  while((ch=getchar_unlocked())!='\n')
	  	{
	  	  if(ch==EOF) break;
	  	  queriesArr[i][curLen]=ch;
	  	  ++curLen;
	  	}
	  queriesArr[i][curLen]='\0';
	  queriesLen[i]=curLen;
	}
  qsort(level3Arr,numStrings,sizeof(Level3Struct),compare);
  /* for(i=0;i<numStrings;++i) */
  /* 	{ */
  /* 	  printf("%d %s\n",level3Arr[i].priority,level3Arr[i].name); */
  /* 	} */
 
  for(i=0;i<numQueries;++i)
	{
	  int j=0;
	  int indexInNames=0;
	  for(j=0;j<numStrings;++j)
		{
		  if(strncmp(queriesArr[i],level3Arr[j].name,queriesLen[i]) == 0)
			{
			  indexInNames=j;
			  break;
			}
		}
	  if(j>=numStrings)
		{
		  //Answer is NO.
		  TempOutBufLen=sprintf(TempBuf,"NO\n");
		  TempBuf+=TempOutBufLen;
		  outBufLen+=TempOutBufLen;
		}
	  else
		{
		  TempOutBufLen=sprintf(TempBuf,"%s\n",level3Arr[indexInNames].name);
		  TempBuf+=TempOutBufLen;
		  outBufLen+=TempOutBufLen;
		}
	}
  write(1,outBuff,outBufLen);
  free(outBuff);
  for(i=0;i<numStrings;++i)
	{
	  free(namesArr[i]);
	}
  free(namesArr);
  for(i=0;i<numQueries;++i)
	{
	  free(queriesArr[i]);
	}
  free(queriesArr);
  return 0;
}
示例#28
0
int VMPI_getchar_unlocked()
{
    return getchar_unlocked();
}
示例#29
0
int main() {
	struct suffix suffixes[1005];
	char A[1005];
	int pos[1005];
	int lcp[1005];
	int nw[1005];
	int *group, *group_bool;
	int start,end,min;
	int ncases;
	int nwords,max_words;
	int global_max;
	int global_index;
	char c;
	int i=0,len=0;
	int j=0,k=0;
	int sum=0;
	i=0;len=0;j=0;k=0;
	sum=0;nwords=1;
	c=getchar_unlocked();
	while(c!='\n') {
		suffixes[i].size=i+1;
		if(c=='$') nwords++;
		A[i]=c;
		c=getchar_unlocked();
		i++;
	}
	max_words=nwords;
	printf("There are %d words\n",max_words);
	suffixes[i].size=i+1;
	A[i]='$';
	strcpy(suffixes[i].ar,A); 
	len=i; 
	nwords=1;
	for(j=0;j<=len;j++) {
		printf("%c",A[j]);
	}
	printf("\n");
	for(j=0;j<=len;j++) {
		for(k=j;k<=len;k++) {
			suffixes[i].ar[k-j]=A[k];
			suffixes[i].nwords=max_words+1-nwords;
		}
		if(suffixes[i].ar[0]=='$') nwords++;
		i--;
	}

	//len+1 because len is 7 
	qsort(suffixes,len+1,sizeof(struct suffix),cmp);
	for(i=0;i<=len;i++) {
		pos[i]=len+1-suffixes[i].size;
		nw[i]=suffixes[i].nwords;
	}
	for(i=0;i<=len;i++) {
		print_suffix(&suffixes[i]);
	}
//	lcp_construct(A,pos,lcp,len);
//	for(i=max_words;i<=len;i++) {
//		printf("%d ",lcp[i]);
//	}
	printf("\n");
	for(i=max_words;i<=len;i++) {
		printf("%d ",nw[i]);
	}
	printf("\n");
	printf("Length is %d\n",len);
	//start indexing from1 to max_word
	group=(int *)malloc((max_words+1)*sizeof(int));
	group_bool=(int *)malloc((max_words+1)*sizeof(int));
	for(i=0;i<=max_words;i++) {
		group[i]=0;
		group_bool[i]=0;
	}
	start=max_words;
	//substring cannot be length
	global_max=0;
	global_index=0;
	start=max_words;
	end=start;		
	while(start<=len && end<=len) {
//		printf("Starting search at %d\n",start);
		sum=0;
		for(i=1;i<=max_words;i++) {
			sum+=group_bool[i];
		}
//		printf("Boolean values:");
//		for(i=1;i<=max_words;i++) {
//			printf("%d ",group_bool[i]);
//		}
//		printf("\n");
		while(sum!=max_words) {
		//	printf("Checking end %d\n",end);
			//check if seen
			if(group_bool[nw[end]]==0) {
				group_bool[nw[end]]=1;
				sum++;
			}
			group[nw[end]]++;
			//			printf("Sum: %d\n",sum);
			//			for(i=1;i<=max_words;i++) {
			//				printf("%d ",group_bool[i]);
			//			}
			//			printf("\n");
			//			printf("%d %d\n",start,end);
//		printf("Group/Boolean values ending at %d\n",end);
//		for(i=1;i<=max_words;i++) {
//			printf("%d ",group[i]);
//		}
//		printf("\n");
//		for(i=1;i<=max_words;i++) {
//			printf("%d ",group_bool[i]);
//		}
//		printf("\n");
			end++;
		}	
		end--;
		printf("Occurence at indexes %d %d\n",start,end);
		min=lcp_two(&suffixes[start],&suffixes[end]);
		if(min>global_max) {
			global_max=min;
			global_index=start;
		}
		while(sum==max_words) {
			//remove first entry
			group[nw[start]]--;
			if(group[nw[start]]==0) {
				group_bool[nw[start]]=0;
				sum--;
			}
			start++;
//			printf("Group/boolean values beginning at %d ending at %d\n",start,end);	
//			for(i=1;i<=max_words;i++) {
//				printf("%d ",group[i]);
//			}
//			printf("\n");
//			for(i=1;i<=max_words;i++) {
//				printf("%d ",group_bool[i]);
//			}
//			printf("\n");
			if(sum==max_words) {
				printf("Occurence at indexes %d %d\n",start,end);
				min=lcp_two(&suffixes[start],&suffixes[end]);
				if(min>global_max) {
					global_max=min;
					global_index=start;
				}
			}
		}
		end++;
	}	
//	global_max=0;
	printf("%d %d\n",global_max,global_index);
	printf("The longest common substring (not unique)\n");
	for(i=0;i<global_max;i++) {
		printf("%c",suffixes[global_index].ar[i]);
	}
	printf("\n");
	return 0;
}
示例#30
0
文件: getchar.c 项目: dennis95/dennix
int getchar(void) {
    flockfile(stdin);
    int result = getchar_unlocked();
    funlockfile(stdin);
    return result;
}