![:D](./images/smilies/icon_biggrin.gif)
![:)](./images/smilies/icon_smile.gif)
![:wink:](./images/smilies/icon_wink.gif)
Moderator: Board moderators
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <list>
#include <stack>
#include <iomanip>
#include <bitset>
using namespace std;
int t, m, n, ans;
char piece;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%c %d %d", &piece, &m, &n);
/* code to solve the problem */
}
return 0;
}
You're correct in your observation.facug91 wrote:Well, I've already found why. 'scanf' ignore white spaces, but evidently not newlines, so 'piece' reads the newlines instead the char it should. I solved it putting 'getchar()' after each 'scanf'
Code: Select all
int t, m, n, ans;
char piece;
int main() {
/* The "\n" after the "%d" handles the newline character so it's not left in the input stream */
scanf("%d\n", &t);
while (t--) {
/* The "\n" after the "%d" handles the newline character so it's not left in the input stream */
scanf("%c %d %d\n", &piece, &m, &n);
/* Code to solve the problem */
}
return 0;
}
Code: Select all
#include <stdio.h>
int minimo(int a, int b);
int main(){
int t;
char p;
int m;
int n;
int i;
scanf("%d",&t);
for(i=0;i<t;i++){
fflush(stdin);
scanf("%c %d %d", &p, &m, &n);
if(p == 'Q'){
printf("%d\n", minimo(m,n));
}
if(p == 'r'){
printf("%d\n", minimo(m,n));
}
if(p == 'k'){
printf("%d\n", (m*n + 1)/2);
}
if(p == 'K'){
printf("%d\n", ((m+1)/2) * ((n+1)/2));
}
}
return 0;
}
int minimo(int a, int b){
if(a < b){
return a;
}
else{
return b;
}
}
Code: Select all
#include <stdio.h>
#include <stdlib.h>
int minimo(int a, int b);
int main(){
int t;
char p;
int m;
int n;
int i;
scanf("%d",&t);
setbuf(stdin, NULL);
for(i=0;i<t;i++){
scanf("%c %d %d", &p, &m, &n);
setbuf(stdin, NULL);
if(p == 'Q'){
printf("%d\n", minimo(m,n));
}
if(p == 'r'){
printf("%d\n", minimo(m,n));
}
if(p == 'k'){
printf("%d\n", (m*n + 1)/2);
}
if(p == 'K'){
printf("%d\n", ((m+1)/2) * ((n+1)/2));
}
}
return 0;
}
int minimo(int a, int b){
if(a < b){
return a;
}
else{
return b;
}
}