/*
 *更新sqlite3 数据库数据
 *author  mleaf_hexi
 *mail:350983773@qq.com
 */
void updata_data(sqlite3 * db)
{
    int num,age,score;
    char name[20];
 
    printf("please input the number you want to updata\n");
    scanf("%d",&num);
    getchar();
    printf("input the name: ");
    scanf("%s",name);
    getchar();
    printf("input the age: ");
    scanf("%d",&age);
    getchar();
    printf("input the score ");
    scanf("%d",&score);
    getchar();
 
//  char sql[1024];
//  sprintf(sql,"update student set name='%s',age='%d',score='%d' where number='%d'",name,age,score,num);
    char *sql=sqlite3_mprintf("update student set name='%s',age='%d',score='%d' where number='%d'",name,age,score,num);
 
    if(sqlite3_exec(db,sql,NULL,NULL,&errmsg) != SQLITE_OK)
    {
        perror("sqlite3_exec_update");
        exit(-1);
    }
    else
        printf("update success!!\n");
    return;
 
}
Example #2
0
int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
        int n;
        scanf("%d",&n);
        int shop[n];

        int i=0;
        long int sum=0;
        while(i<n)
        {
            scanf("%d",&shop[i]);
            i++;
        }

        qsort(shop,n,sizeof(shop[0]),comp);

        i=n-3;
        while(i>=0)
        {
            sum+=shop[i];
            i=i-3;
        }

        printf("%ld\n",sum);
    }
    return 0;
}
Example #3
0
int main(int argc, char **argv)
{
  printf("Enter two end points of the line to be drawn:\n");
  printf("\n************************************");
  printf("\nEnter Point1( X1 , Y1):\n");
  scanf("%lf%lf",&X1,&Y1);
  printf("\n************************************");
  printf("\nEnter Point1( X2 , Y2):\n");
  scanf("%lf%lf",&X2,&Y2);
  
  /* Initialise GLUT library */
  glutInit(&argc,argv);
  /* Set the initial display mode */
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  /* Set the initial window position and size */
  glutInitWindowPosition(0,0);
  glutInitWindowSize(640,480);
  /* Create the window with title "DDA_Line" */
  glutCreateWindow("DDA_Line");
  /* Initialize drawing colors */
  Init();
  /* Call the displaying function */
  glutDisplayFunc(LineDDA);
  /* Keep displaying untill the program is closed */
  glutMainLoop();
  return 0;
}
Example #4
0
void alta(int proximo,int* codigo,char descripcion[][50],float* importe, int* cantidad, int maximo)
{
	int  i;
	
	for(i=1; i<=maximo; i++)
	 {
		codigo=i;
		
			printf("\nCodigo: %d", codigo);
			printf ("\nDescripcion: ");
			scanf("%s", & descripcion[i]);
		
			printf("Importe: ");
			scanf("%f", & importe[i]);
			
			printf("Cantidad: ");
			scanf("%d", & cantidad[i]);
			
			
			if(i==maximo)
			break;
	 }
	 
	
}
Example #5
0
int main(void)
{
  int index;
  char* inputString;
  char* target;
  
  inputString = malloc(sizeof(char)*50);
  
  printf("Enter a string: ");
  scanf("%s", inputString);
  
  printf("You typed: \'%s\'\n", inputString);
  
  printf("Enter an index: ");
  scanf("%d", &index);
  printf("The index entered is: %d\n", index);
  
  target = getCharAtIndex(inputString, index);

  printf("The memory address pointed at by target is: %p\n", target);
  printf("The address of target is: %p\n", &target);
  printf("The character that is pointed at by target is: %c\n", *target);
  
  return 0;
}
int main()
{
    long long int N,i,j,a[3],max,k,sum;
    scanf("%lld",&N);
    for(i=1;i<=N;i++)
    {
        max=0;
        for(j=0;j<3;j++)
        {
            scanf("%lld",&a[j]);
            if(a[j]>=max)
            {
                max=a[j];
                k=j;
            }
        }

        sum=0;
        for(j=0;j<3;j++)
        {
            if(j==k)
                continue;
            sum=sum+a[j];
        }

        if(sum<=max)
            printf("Wrong!!\n",i);
        else
            printf("OK\n");
    }
    return 0;
}
int main()
{
	int i;
	scanf("%d%d",&n,&m);
	scanf("%s",dr+1);
	jc[0]=inv[0]=1;
	for(i=1;i<=n;i++)
	{
		jc[i]=jc[i-1];
		cheng(jc[i],i);
		inv[i]=power(jc[i],Mod-2);
	}
	int ans=0;
	int val=zuhe(n-1,m);
	int zeng=9;
	for(i=n;i>=1;i--)
	{
		int now=dr[i]-'0';
		cheng(now,val);
		jia(ans,now);
		now=zuhe(i-2,m);
		cheng(now,zeng);
		jia(val,now);
		cheng(zeng,10);
	}
	printf("%d\n",ans);
	return 0;
}
Example #8
0
int main(){
	int n, k;
	int macas[100];
	int q;
	int caixas[100];
	int i;
	scanf("%d %d", &n, &k);

	for(i = 0; i < n; i++){
		scanf("%d", &macas[i]);
	}

	scanf("%d", &q);

	int primeira = 0;
	int erguidas = 0, j;
	int count = 0;
	for(i = 0; i < q; i++){
		scanf("%d", &primeira);
		primeira--;
		for(erguidas = 0, count = 0; primeira < n && count < k; primeira++, count++){
			erguidas += macas[primeira];
		}
		printf("%d\n", erguidas);
	}
	return 0;
}
Example #9
0
int main(void) {
  setlocale(LC_ALL, "portuguese");

  int tipo;
  float investimento, valorCorrigido;

  do{
    printf("Informe o tipo de investimento:\n");
    printf("[1] Poupança     [2] Renda fixa\n");
    scanf("%i", &tipo);
  } while (tipo!=1 && tipo!=2);

  printf("Informe o valor do investimento:\n");
  scanf("%f", &investimento);


  switch (tipo) {
    case 1:
      valorCorrigido=investimento*1.03;
      break;
    case 2:
      valorCorrigido=investimento*1.05;
      break;
  }

  printf("O valor corrigido após 30 dias é igual a R$ %.2f.\n", valorCorrigido);

  return 0;
}
Example #10
0
int main (void) {
    int casos,
        x,
        y,
        rafaelResult,
        betoResult,
        carlosResult;

    scanf("%d", &casos);

    for (; casos > 0; casos--) {
        scanf("%d %d", &x, &y);

        rafaelResult = rafaelFn(x, y);
        betoResult = betoFn(x, y);
        carlosResult = carlosFn(x, y);

        // Assuma que nunca haverá empates.

        if (rafaelResult > betoResult && rafaelResult > carlosResult) {
            printf("Rafael ganhou\n");
        }
        else if (betoResult > rafaelResult && betoResult > carlosResult) {
            printf("Beto ganhou\n");
        }
        else {
            printf("Carlos ganhou\n");
        }
    }

    return 0;
}
Example #11
0
File: main.c Project: Sylyon/C
int main()
{
    int nombreMystere=0, nombre=0, compteur=1, niveaux, nombremax, jouer=1;
    const int MIN=1;

 srand(time(NULL));


printf("====Choix du niveaux=====\n\n");
printf("  1. Debutant \n");
printf("  2. intermediaire\n");
printf ("  3. Difficile\n");
printf ("   Votre Choix?\n");
scanf("%d", &niveaux);

switch (niveaux)
{
  case 1 :
    nombremax=100;
    break;

  case 2 :
    nombremax =500;
    break;

  case 3 :
    nombremax=1000;
    break;

  default:
    printf("Je n'est pas compris");
}

nombreMystere=(rand()%(nombremax-MIN+1))+MIN;

do
{
printf("Quel est votre nombre?\n");
scanf("%d", &nombre);

if (nombre>nombreMystere)

    printf("C'est moins \n");

else if (nombre<nombreMystere)


    printf("c'est plus\n");

else


    printf("Bravo vous avez trouvee le chiffre mystere en %d coup\n", compteur);
    compteur++;

    }
     while( nombre !=nombreMystere);
    return 0;

    }
Example #12
0
int main(){
long long int t,g,sd=0,p[12345],i,d[12345],j,h,result,a;
char str[12345],b[12345],o[12345],f[12345];
scanf("%lld",&t);
while(t--){
scanf("%s",str);
g=strlen(str);
a=g/2;
for(i=0;i<g;i++){
p[i]=str[i];}
//strcpy(b,str);
result = is_palindrome(str);

   if ( result == 1 ){
printf("0\n");
}
else{ if((g%2)==0){
for(i=0;i<a;i++){
d[i]=p[g-(i+1)]-p[i];}
j=a;
while(j--){
sd=sd+d[j];}
}
else{
for(i=0;i<a;i++){
d[i]=p[g-i-1]-p[i];}
h=a;
while(h--){
sd=sd+d[h];}}
printf("%lld",sd);}
}return 0;
}
Example #13
0
File: 10533.cpp Project: dibery/UVa
int main()
{
    int t;
    scanf( "%d", &t );

    for( int i = 2; i < 1000; ++i )
        if( check( i ) )
            prime_num[ ++put ] = i;
    for( int i = 2; i < 1000000; ++i )
        is_prime[ i ] = check( i );
    for( int i = 1, tmp, sum; i < 1000000; ++i )
    {
        tmp = i;
        sum = 0;
        while( tmp )
        {
            sum += tmp % 10;
            tmp /= 10;
        }
        table[ i ] = is_prime[ sum ] && is_prime[ i ];
    }
    for( int i = 1; i < 1000000; ++i )
        out[ i ] = out[ i-1 ] + table[ i ];

    while( t-- )
    {
        int ans = 0, l, h;
        scanf( "%d %d", &l, &h );
        printf( "%d\n", out[ h ] - out[ l-1 ] );
    }

    return 0;
}
Example #14
0
/*
*插入数据到sqlite3 数据库
*author  mleaf_hexi
*mail:350983773@qq.com
*/
void insert_data(sqlite3 *db)
{
    int number,age,score;
    char name[20];
 
    printf("input the number: ");
    scanf("%d",&number);
    getchar();
    printf("input the name: ");
    scanf("%s",name);
    getchar();
    printf("input the age: ");
    scanf("%d",&age);
    getchar();
    printf("input the score ");
    scanf("%d",&score);
    getchar();
    char *sql=sqlite3_mprintf("insert into student values('%d','%s','%d','%d')",number,name,age,score);
    if(sqlite3_exec(db,sql,NULL,NULL,&errmsg) != SQLITE_OK)
    {
        perror("sqlite3_exec");
        exit(-1);
    }
    else
        printf("insert success!!\n");
    return;
}
Example #15
0
int main()
{
    /*freopen("/sdcard/coding/anwar/oj/in.txt", "rt", stdin);
    freopen("/sdcard/coding/anwar/oj/out.txt", "wt", stdout);
    
    clock_t start, end;
    double time_spent;
    start = clock();*/
    
    int tc;
    int current_tc;
    
    scanf("%d", &tc);
    
    for (current_tc = 1; current_tc <= tc; current_tc++) {
        char num[100001];
        int length;
        
        scanf("%s", num);
        length = strlen(num);
        
        printf("Case %d: ", current_tc);
        
        if (isDividedBy3(num, length) && isDividedBy5(num, length)) printf("FizzBuzz\n");
        else if (isDividedBy3(num, length) && !isDividedBy5(num, length)) printf("Fizz\n");
        else if (isDividedBy5(num, length) && !isDividedBy3(num, length)) printf("Buzz\n");
        else printf("Null\n");
    }
    
    /*end = clock();
    time_spent = (double)(end - start) / CLOCKS_PER_SEC;
    printf("Time spent: %0.9lf\n", time_spent);*/
    
    return 0;
} // end main
int main(){
	int n;
	long long int sum = 0;
	std::vector<int> S; // S[k] represents S[0~k] += value 
	S.push_back(0);
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		int command;
		int x, k;
		scanf("%d", &command);
		switch (command){
		case 1:
			scanf("%d%d", &k, &x);
			S[k - 1] += x;
			sum += k*x;
			break;
		case 2:
			scanf("%d", &x);
			// balance
			S[S.size() - 1] -= x;
			S.push_back(x);
			sum += x;
			break;
		case 3:
			sum -= S[S.size() - 1];
			S[S.size() - 2] += S[S.size() - 1];
			S.pop_back();
			break;
		}
		printf("%.6lf\n", (double)sum / S.size());
	}
	return 0;
}
Example #17
0
main()
{
	  int i,j,k,l;
	  int V[120];
      int N;
	  int T;
	  scanf("%d",&T);
	  while (T--)
	  {
		  memset(d,0,sizeof(d));
		  scanf("%d",&N);
		  int sum=0;
		  for (i=1;i<=N;i++)
		  {
			  scanf("%d",&V[i]);
			  sum+=V[i];
		  }
		  int C=sum/2;
		  for (i=1;i<=N;i++)
		  for (j=C;j>=0;j--)
		  {
			  if (j>=V[i]) d[j]=d[j]>d[j-V[i]]+V[i]?d[j]:d[j-V[i]]+V[i];
		  }
		  printf("%d\n",abs(sum-d[C]*2));
	  }
	  return 0;
}
Example #18
0
void Lue(int *pi, double *pd)
{
    printf("Anna int luku : ");
    scanf("%d", pi);
    printf("Anna double luku : ");
    scanf("%lf", pd);
}
int main()//Função principal
{
	
	//Procedimento cabecalho
	cabecalho();
	
	//Declaração de variáveis
	float idade[3];
	float peso[3];
	int i;
	
	//Obervação coloquei o laço indo até 3 para testar, tinha que ir até 10
	//de acordo com o exercicio
	for(i=0; i < 3; i++)
	{
		printf("\nIntroduza a idade da pessoa %d\n",i+1);
		scanf("%f",&idade[i]);
		
		printf("\nIntroduza o peso da pessoa %d\n",i+1);
		scanf("%f",&peso[i]);
		
	}
	
	//Impressão de resultados
	printf("\n****-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_****\n");
	printf("\nA idade da pessoa que tem o maior peso = %.0f\n",
	idade_e_maior_peso(peso,idade)  );
	printf("\nO peso da pessoa que tem a menor idade = %.0f\n",
	peso_e_menor_idade(peso,idade) );
	printf("\n****-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_****\n");
	
	system("pause");
	return 0;
}
Example #20
0
int main() {
    int n, m, s, e, w;
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            if(i==j) d[i][j]=0;
            else d[i][j] = INF;
        }
    }
    for(int i=0; i<m; i++) {
        scanf("%d %d %d", &s,&e,&w);
        if(d[s][e] > w) d[s][e] = w;
    }
    for(int k=1; k<=n; k++) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if(d[i][j] > d[i][k]+d[k][j]) {
                    d[i][j] = d[i][k]+d[k][j];
                }
            }
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            if(d[i][j]>=INF) printf("0 ");
            else printf("%d ", d[i][j]);
        }
        puts("");
    }
    return 0;
}
Example #21
0
int main()
{
  /* Deklaracija i inicijalizacija potrebnih promenljivih. */
  int n, i;
  int broj_a = 0, broj_e = 0, broj_i = 0, broj_o = 0, broj_u = 0;
  char c;

  /* Ucitava se broj karaktera. */
  printf("Unesite broj n: ");
  scanf("%d", &n);

  /* Vrsi se provera ispravnosti ulaza. */  
  if (n < 0) {
    printf("Greska: neispravan unos.\n");
    return -1;
  }

  /* Kako je korisnik nakon unosa broja n uneo oznaku za novi red,
     potrebno je preskociti taj novi red jer bi u suprotnom on bio
     ucitan kao prvi od n karaktera (oznaka za novi red je
     regularan karakter kao sto je to 'a' ili ' ').*/
  getchar();
  
  /* Ucitavaju se karakteri i broje se samoglasnici. */
  for (i = 0; i < n; i++) {
    scanf("%c", &c);

    switch (c) {
    case 'a':
    case 'A':
      broj_a++;
      break;
    case 'e':
    case 'E':
      broj_e++;
      break;
    case 'i':
    case 'I':
      broj_i++;
      break;
    case 'o':
    case 'O':
      broj_o++;
      break;
    case 'u':
    case 'U':
      broj_u++;
      break;
    }
  }

  /* Ispis rezultata. */
  printf("Samoglasnik a: %d\n", broj_a);
  printf("Samoglasnik e: %d\n", broj_e);
  printf("Samoglasnik i: %d\n", broj_i);
  printf("Samoglasnik o: %d\n", broj_o);
  printf("Samoglasnik u: %d\n", broj_u);

  return 0;
}
Example #22
0
int opr_login(ADMIN_LIST* list){//管理员登陆,根据返回值确定类型
	char name[20] = {};
	int password;
	char pass[20] = {};
	int i = 0;
	printf("输入管理员帐号:\n");
	scanf("%s", name);
	scanf("%*[^\n]");
	scanf("%*c");
	printf("输入密码:\n");
	while(i != 20){
		pass[i] = getch();
		if(pass[i] == '\n')
			break;
		i++;
	}
	pass[i] = '\0';
	sscanf(pass, "%d", &password);
	int tmp = check(list, name);
	ADMIN_NODE* node = admin_find(list, name);
	if(tmp >= 0){
		if(tmp == password && node->admin->limit ==1)
			return 1;
		else if(tmp == password && node->admin->limit == 0)
			return 2;
		else
			return 0;
	}
	else
		return 0;
}
int main(int argc , char **argv)
{
	if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1;
	int t,m,n,i,j,**floor,val;scanf("%d",&t);
	while(t--){
		scanf("%d %d",&m,&n);
		floor=(int**)calloc(m,sizeof(int*));
		for(i=0;i<m;++i){
			floor[i]=(int*)calloc(n,sizeof(int));
			for(j=0;j<n;++j){
				scanf("%d",&floor[i][j]);
			}
		}
		for(i=1;i<m;++i){
			for(j=0;j<n;++j){
				val = floor[i-1][j];
				if(j>0)val = val>floor[i-1][j-1] ? val : floor[i-1][j-1] ;
				if(j<n-1)val = val>floor[i-1][j+1] ? val : floor[i-1][j+1];
				
				floor[i][j]+=val;
			}
		}
		if(debug){
			printf("\n\n");
			for(i=0;i<m;++i){
				for(j=0;j<n;++j)printf("%d ",floor[i][j]);
				printf("\n");
			}
		}
		for(i=0;i<n;++i)val=val>floor[m-1][i]?val:floor[m-1][i];
		printf("%d\n",val);
	}
	return 0;
}
Example #24
0
int main() {
    int T;
    scanf("%d", &T);

    for (int i = 0; i < T; i++) {
        int N;
        scanf("%d", &N);

        double x = 0;
        double y = 0;
        double teta = 0;

        for (int j = 0; j < N; j++) {
            char command[3];
            double number;
            scanf("%s %lf", command, &number);
            processCommand(x, y, teta, command, number);
        }

        printf("%d\n", int(distance(x, y)));
    }


    return 0;
}
Example #25
0
int main() {
  int a[100], b[100], m, n, c, sorted[200];
 
  printf("Input number of elements in first array\n");
  scanf("%d", &m);
 
  printf("Input %d integers\n", m);
  for (c = 0; c < m; c++) {
    scanf("%d", &a[c]);
  }
 
  printf("Input number of elements in second array\n");
  scanf("%d", &n);
 
  printf("Input %d integers\n", n);
  for (c = 0; c < n; c++) {
    scanf("%d", &b[c]);
  }
 
  merge(a, m, b, n, sorted);
 
  printf("Sorted array:\n");
 
  for (c = 0; c < m + n; c++) {
    printf("%d\n", sorted[c]);
  }
 
  return 0;
}
int main() {
    int caseNum;

    scanf("%d", &caseNum);
    for (int caseCount=1; caseCount<=caseNum; caseCount++) {
        int wallNum, prevHeight;
        int highJump = 0;
        int lowJump = 0;

        scanf("%d", &wallNum);
        for (int i=0; i<wallNum; i++) {
            int height;

            scanf("%d", &height);
            if (i > 0) {
                if (height > prevHeight) highJump++;
                else if (height < prevHeight) lowJump++;
            }
            prevHeight = height;
        }
        printf("Case %d: %d %d\n", caseCount, highJump, lowJump);
    }

    return 0;
}
Example #27
0
int main()
{
    int cc;
    int i,r;
    double from,mid,to;
 
    scanf("%d",&cc);
    for(;cc;cc--)
    {
        from=0;
        to=0;
        scanf("%d%d",&piec,&peoplec);
        peoplec++;
        for(i=0;i<piec;i++)
        {
            scanf("%d",&r);
            pie[i]=r*r*pi;
        }
         
        qsort(pie,piec,sizeof(double),cmp);
 
        to=pie[0]+1;
        while(to-from>1e-6)
        {
            mid=(from+to)/2;
            if(test(mid)) from=mid;
            else to=mid;
        }
 
        printf("%.4f\n",(from+to)/2);
    }
 
    return 0;
}
Example #28
0
void main() {

    int array[25],limit,temp,i,j;

    printf("enter the limit: ");
    scanf("%d",&limit);
    printf("Enter the numbers: ");

    for(i=0;i<limit;i++) {

        scanf("%d",&array[i]);
    }
    for(i=0;i<limit-1;i++) {

        for(j=i+1;j<limit;j++)

            if(array[i]>array[j])
            {
                temp=array[i];
                array[i]=array[j];
                array[j]=temp;
            }
    }
    printf("the sorted array is: ");

    for(i=0;i<limit;i++)

        printf("%d\t",array[i]);
}
Example #29
0
int main () {
  int count;
  int i, j, k;
  int n;

  scanf ("%d", &count);
  for (i=0; i<count; i++) {
    memset (flag, 0, sizeof(int)*N);
    scanf ("%d", &n);
    getchar();
    for (j=0; j<n; j++)
      fgets (s[j], sizeof(s[j][0])*M, stdin); 
    for (j=0; j<n; j++)
      fgets (d[j], sizeof(d[j][0])*M, stdin);

    /* find immobile sequence */
    for (j=n-1, k=n-1; j>=0; j--) {
      if (!strcmp (s[j],d[k])) { 
        flag[k] = 1;
        k -= 1;
      }
    }
    /* output mobile sequence */
    for (j=n-1; j>=0; j--) {
      if (flag[j] != 1)
        printf ("%s", d[j]);
    }

    printf ("\n");
  }
  return 0;
}
Example #30
0
void main(){
	
	float a[100][100],Trans[100][100];
	int i,j,Rows,columns;
	printf("Enter Size of Matrix: \n");
	printf("Enter No. Of Rows: ");
	scanf(" %d",&Rows);
	printf("Enter No. Of Columns: ");
	scanf(" %d",&columns);
	printf("\nEnter Elements of matrix: \n");
	for(i=0;i<Rows;i++){
		for(j=0;j<columns;j++){
			printf("Enter ELement a%d%d: ",i+1,j+1);
			scanf(" %f",&a[i][j]);
		}
		printf("\n");
	}
	printf("\nTranspose of Matrix: \n");
	for(i=0;i<Rows;i++){
		for(j=0;j<columns;j++){
			Trans[i][j] = a[j][i];
			printf("%g\t",Trans[i][j]);
		}
		printf("\n");
	}
	system("pause");
	
}