Ir ao conteúdo
  • Cadastre-se

Problemas para converter de linguagem C++ para C


Posts recomendados

Olá pessoal estou tendo dificuldades para com esse algoritmo, para transformá-lo em linguagem C, me ajudem por favor?

 

#include <bits/stdc++.h>
#define D(x) cout << #x " = " << (x) << endl
#define endl '\n'

using namespace std;

int dx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int dy[] = {2, -2, 1, -1, 2, -2, 1, -1};

bool valid(int nx, int ny) {
     return (nx >= 0 && nx < 8 && ny >=0 && ny < 8);
}
int main() {
      ios_base::sync_with_stdio(false);cin.tie(NULL);
      string line;
      int tc = 0;
      while (cin >> line && line != "0") {
            vector<vector<int>> a(8, vector<int>(8));
            int x = line[0] - '1', y = line[1] - 'a';
            for (int i = 0; i < 8; ++i) {
                       cin >> line;
                        int xx = line[0] - '1', yy = line[1] - 'a';
                       a[xx][yy] = 1;
                       }
            int ans = 0;
            for (int i = 0; i < 8; ++i) {
                       int nx = x + dx, ny = y + dy;
                       if (valid(nx, ny)) {
                              int tx = nx + 1, ty = ny - 1;
                              int ok = true;
                              if (valid(tx, ty) && a[tx][ty]) ok = false;
                              ty = ny + 1;
                              if (valid(tx, ty) && a[tx][ty]) ok = false;
                              if (ok) ans++;
                              }
                        }
            cout << "Caso de Teste #" << ++tc << ": ";
            cout << ans << " movimento(s)." << endl;
      }
return 0;
}

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!