a czego? bo nie mam pomysłu
- 1
- 2
- Rejestracja:ponad 4 lata
- Ostatnio:ponad 4 lata
- Postów:64

- Rejestracja:ponad 13 lat
- Ostatnio:prawie 3 lata
0
Sprawdziłem kod od @enedil do 10000 (na więcej mi szkoda prądu).
Nie znalazłem błędów.

- Rejestracja:ponad 13 lat
- Ostatnio:prawie 3 lata
0
@crypton: w takim razie możesz użyć jego kodu do debugowania swojego stosując test porównawczy:
bool test(unsigned a, unsigned b) {
int actual = PowMod10(a, b);
int expected = my_pow_mod10(a, b);
if (actual != expected) {
cout << "Error found for a = " << a << ", b = " << b << ", expected: " << expected << ", actual: " << actual << "\n";
return false;
}
return true;
}
int main() {
int totalSuccess = 0;
int totalErrors = 0;
int limit = 10000;
for(int a = 1; a < limit; a++) {
for(int b = 1; b < limit; b++) {
if (test(a, b)) {
totalSuccess++;
} else {
totalErrors++;
}
}
}
cout << "Correct results: " << totalSuccess << endl;
cout << "Errors: " << totalErrors << endl;
return 0;
}
no ja domyslam sie w czym problem, w moim kodzie działa to wszystko poprawnie tylko dla a<10, niestesty nie mam pomyslu jak rozszerzyć to rownież na a>10
- Rejestracja:ponad 4 lata
- Ostatnio:ponad 4 lata
- Postów:64
0
#include <iostream>
#include<cmath>
using namespace std;
int LiczenieOstCyfryPotegi(int a, int b)
{
int wynik;
if (b == 0)
return 1;
else if (a == 1)
return 1;
else if (a == 2)
{
if (b % 4 == 1)
return 2;
else if (b % 4 == 2)
return 4;
else if (b % 4 == 3)
return 8;
else if (b % 4 == 0)
return 6;
}
else if (a == 3)
{
if (b % 4 == 1)
return 3;
else if (b % 4 == 2)
return 9;
else if (b % 4 == 3)
return 7;
else if (b % 4 == 0)
return 1;
}
else if (a == 4)
{
if (b % 2 == 0)
return 6;
else return 4;
}
else if (a == 5)
{
return 5;
}
else if (a == 6)
{
return 6;
}
else if (a == 7)
{
if (b % 4 == 1)
return 7;
else if (b % 4 == 2)
return 9;
else if (b % 4 == 3)
return 3;
else if (b % 4 == 0)
return 1;
}
else if (a == 8)
{
if (b % 4 == 1)
return 2;
else if (b % 4 == 2)
return 4;
else if (b % 4 == 3)
return 8;
else if (b % 4 == 0)
return 6;
}
else if (a == 9)
{
if (b % 2 == 0)
return 1;
else return 9;
}
}
int main()
{
int ilosc, a, b;
cin >> ilosc;
int* tab = new int[ilosc];
for (int i = 0; i < ilosc; i++)
{
cin >> a >> b;
tab[i]= LiczenieOstCyfryPotegi(a, b);
}
for (int i = 0; i < ilosc; i++) {
cout << tab[i] << endl;
}
}
Użyj debugger i zobacz do jakiego ifa wejdziesz wpisując np 12, a do jakiego powinieneś wejść
- Rejestracja:ponad 4 lata
- Ostatnio:ponad 4 lata
- Postów:64
0
#include <iostream>
#include<cmath>
using namespace std;
int LiczenieOstCyfryPotegi(int a, int b)
{
int wynik;
if (b == 0)
return 1;
else if ((a == 1)||(a%10==1))
return 1;
else if ((a == 2) || (a%10==2))
{
if (b % 4 == 1)
return 2;
else if (b % 4 == 2)
return 4;
else if (b % 4 == 3)
return 8;
else if (b % 4 == 0)
return 6;
}
else if ((a == 3)||(a%10==3))
{
if (b % 4 == 1)
return 3;
else if (b % 4 == 2)
return 9;
else if (b % 4 == 3)
return 7;
else if (b % 4 == 0)
return 1;
}
else if ((a == 4)||(a%10==4))
{
if (b % 2 == 0)
return 6;
else return 4;
}
else if ((a == 5)||(a%10==5))
{
return 5;
}
else if ((a == 6)||(a%10==6))
{
return 6;
}
else if ((a == 7)||(a%10==7))
{
if (b % 4 == 1)
return 7;
else if (b % 4 == 2)
return 9;
else if (b % 4 == 3)
return 3;
else if (b % 4 == 0)
return 1;
}
else if ((a == 8)||(a%10==8))
{
if (b % 4 == 1)
return 2;
else if (b % 4 == 2)
return 4;
else if (b % 4 == 3)
return 8;
else if (b % 4 == 0)
return 6;
}
else if ((a == 9)||(a%10==9))
{
if (b % 2 == 0)
return 1;
else return 9;
}
}
int main()
{
int ilosc, a, b;
cin >> ilosc;
int* tab = new int[ilosc];
for (int i = 0; i < ilosc; i++)
{
cin >> a >> b;
tab[i] = LiczenieOstCyfryPotegi(a, b);
}
for (int i = 0; i < ilosc; i++) {
cout << tab[i] << endl;
}
}
okej, chyba git, bo na SPOJ przeszło :))))
dzięki ślicznie za pomoc i czas na walkę z moją niewiedzą ;>

- Rejestracja:prawie 12 lat
- Ostatnio:3 minuty
- Lokalizacja:Szczecin
- 1
- 2
Zarejestruj się i dołącz do największej społeczności programistów w Polsce.
Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.