LMysk
-
Pranešimai
40 -
Užsiregistravo
-
Lankėsi
-
Atsiliepimai
0%
Turinio tipas
Forumas
Kalendorius
Parduotuvė
Akademija
Skelbimai
LMysk Pranešimai
-
-
-
Kada atsiskaityti reikia?
Jei butu gerai, iki rytoj ryte.
-
Kas galetu padaryti? Tikrai atsilyginsiu. I PM.
-
-
Pradžioje nenurodei sus = 0 ? Manyčiau, neturiu compilerio patikrinti. Pagal viską turėtų random values gražinti iš memory ir to pasekoje tau ir gaunasi tokie skaičiai
Aciu, kad veikia :)
-
Man reikia pagalbos!
Spausdinama programą, dėl užpildytos neteisingų duomenių, kažkaip nurodyta rezultatus: -869633222.
#include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <random> #include <algorithm> #include <conio.h> using namespace std; int main() { srand(time(0)); int n = 8; int i; int sus; std::string mName[8] = { "Linas", "Adomas", "Lina", "Vardas", "56Gintaute", "Paulius", "Ugnius", "Karolis" }; std::string mCity[8] = { "Vilnius", "Kaunas", "Marijampole", "Garliava", "56Prienai", "Prienai", "Birstonas", "Alytus" }; std::string mAge[8] = { "100", "25", "85", "23", "a74", "125", "15", "98" }; std::string mPin[8] = { "152687", "145236", "147855", "985632", "a741258", "2335", "4578", "23654" }; for (int i = 0; i < n; i++) { int generated = rand() % 100 + 1; if (generated >= 10) { cout << mName[i] << " - geras" << endl; } else cout << mName[i] << " - blogas" << endl; } for (int i = 0; i < n; i++) { int generated = rand() % 100 + 1; if (generated >= 10) { cout << mCity[i] << " - geras" << endl; } else cout << mCity[i] << " - blogas" << endl; } for (int i = 0; i < n; i++) { int generated = rand() % 100 + 1; if (generated >= 10) { cout << mAge[i] << " - geras" << endl; } else cout << mAge[i] << " - blogas" << endl; } for (int i = 0; i < n; i++) { int generated = rand() % 100 + 1; if (generated >= 10) { cout << mPin[i] << " - geras" << endl; } else cout << mPin[i] << " - blogas" << endl; } for (i = 1; i <= 99; ++i) { string name = mName[rand() % 8]; string city = mCity[rand() % 8]; string age = mAge[rand() % 8]; string pin = mPin[rand() % 8]; cout << "\n\nEnter your name \n " << name << endl; if (name =="56Gintaute") { cout<< "Blogai ivesta duomeni." << endl; sus += 1; } if (name == "Vardas") { cout << "Negalima kopijuoti." << endl; sus += 1; } cout << "Enter your city \n " << city << endl; if (city == "56Prienai") { cout << "Blogai ivesta duomeni." << endl; sus += 1; } cout << "Enter your age \n " << age << endl; if (age == "a74") { cout << "Blogai ivesta duomeni." << endl; sus += 1; } cout << "Enter your pin \n " << pin << endl; if (pin == "a741258") { cout << "Blogai ivesta duomeni." << endl; sus += 1; } cout << "===============================\n "; cout << "Complete information: \n "; cout << "===============================\n "; cout << "Name: \t" << name << endl; cout << "City: \t" << city << endl; cout << "Age: \t" << age << endl; cout << "Pin: \t" << pin << endl; cout << "===============================\n "; } cout << "Is viso uzpildyta: " << i << endl; cout << "Neteisingai duomenys" << sus << endl; system("pause"); return 0; }
-
Tiksli užduoties formuluotė? :D
Taip, bet del tikimybes, nelabai gerai mokau programuoti...
-
Uzduotis - ikeliau nuotrauka.
Reiketu programuoti cikla, nelabai nesupratau... Gal kas galetu padeti?
Programavau:
#include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <random> using namespace std; int main() { srand(time(NULL)); std::string mName[10] = { "Linas", "Adomas", "Lina", "Vardas", "Gintaute", "Paulius", "Ugnius", "Karolis" }; std::string mCity[10] = { "Vilnius", "Kaunas", "Marijampole", "Garliava", "56Prienai", "Prienai", "Birstonas", "Alytus" }; std::string mAge[10] = { "100", "25", "85", "23", "74", "125", "1a5", "203" }; std::string mPin[10] = { "152687", "145236", "147855", "985632", "741258", "-2335", ".4578" }; string name = mName[rand() % 10]; string city = mCity[rand() % 10]; string age = mAge[rand() % 10]; string pin = mPin[rand() % 10]; cout << "Enter your name \n " << name<< endl; cout << "Enter your city \n " << city<< endl; cout << "Enter your age \n " << age<< endl; cout << "Enter your pin \n " << pin << endl; cout << "===============================\n "; cout << "Complete information: \n "; cout << "===============================\n "; cout << "Name: \t" << name << endl; cout << "City: \t" << city << endl; cout << "Age: \t" << age << endl; cout << "Pin: \t" << pin << endl; cout << "===============================\n "; system("pause"); return 0; }
-
Sveiki,
ieskau zmogu uz galetu C++ padaryta namu darbu uzduocius. Derinta su kaina.
-
Tai idėk čia užduotį, pats ruošiuosi egzaminui, galiu pabandyt jėgas :)
Jau išsiunčiau tau asmeniškai :)
-
Sveiki,
gal yra galinčių atlikti užduotį (apie paieškas). Labai padėtų bet kokia pagalba(kodas), jeigu reikės bus galima atsilyginti.
Kas galės? Tada duosiu užduočius :) Labai lauksiu.
-
Viską programavau... Kažkaip dėl rezultato. Nes turėtų būti tikslu gaut 000. Gal žinote apie Missionaries and Cannibals (Depth-First Search).
Todėl čia programavau, bet kažkaip... Lauksiu jūsų patarimo.
#include <string> #include <utility> #include <vector> #include <iostream> using namespace std; vector< pair< int, pair < int, int > > > newStatesSet(pair< int, pair < int, int > > state) { vector< pair< int, pair < int, int > > > newStatesSet; int C = state.second.first, M = state.second.second; if (state.first == 0) { if (C >= 1) newStatesSet.push_back(make_pair(1, make_pair(C - 1, M))); if (M >= 1) newStatesSet.push_back(make_pair(1, make_pair(C, M - 1))); else if (C >= 2) newStatesSet.push_back(make_pair(1, make_pair(C - 2, M))); if (C >= 1 && M >= 1) newStatesSet.push_back(make_pair(1, make_pair(C - 1, M - 1))); else if (M >= 2) newStatesSet.push_back(make_pair(1, make_pair(C, M - 2))); } else { C = 3 - C; M = 3 - M; if (C >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 1, 3 - M))); if (M >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C, 3 - M + 1))); else if (C >= 2) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 2, 3 - M))); if (C >= 1 && M >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 1, 3 - M + 1))); else if (M >= 2) newStatesSet.push_back(make_pair(0, make_pair(3 - C, 3 - M + 2))); } return newStatesSet; } bool validState(pair<int, pair<int, int> > state) { int C = state.second.first, M = state.second.second; if (C > M && M != 0) return false; C = 3 - C, M = 3 - M; if (C > M && M != 0) return false; return true; } bool depthLimitedSearch(pair<int, pair<int, int> > source, pair<int, pair<int, int> > goal, int depth, vector< pair< int, pair < int, int > > > &ans) { if (source == goal) return true; if (depth <= 0) return false; vector< pair< int, pair < int, int > > > leafs = newStatesSet(source); for (auto &leaf : leafs) if (validState(leaf)) { if (depthLimitedSearch(leaf, goal, depth - 1, ans)) { ans.push_back(leaf); return true; } } } string form(int stateNos, string character) { string rep = ""; for (int i = 1; i <= 3; i++) if (stateNos >= i) rep.append(character); else rep.append(" "); return rep; } void displayState(pair<int, pair<int, int> > state) { string rep = ""; rep.append(form(state.second.first, "C")); rep.append(form(state.second.second, "M")); for (int i = 1; i <= 6; i++) { if (state.first == 0 && i == 2) rep.append("B"); else if (state.first == 1 && i == 5) rep.append("B"); else rep.append(" "); } rep.append(form(3 - state.second.first, "C")); rep.append(form(3 - state.second.second, "M")); cout << rep << endl; } void iterativeDeepeningSearch(pair<int, pair<int, int> > source, pair<int, pair<int, int> > goal) { vector< pair<int, pair<int, int> > > ans; for (int i = 1; i <= 25; i++) { vector<pair<int, pair<int, int> > >vec; depthLimitedSearch(source, goal, i, vec); if (vec.size()>0) { ans = vec; break; } } cout << ""; displayState(source); for (auto it = ans.rbegin(); it != ans.rend(); ++it) displayState(*it); } int main() { pair<int, pair<int, int> > source = make_pair(0, make_pair(3, 3)); pair<int, pair<int, int> > goal = make_pair(1, make_pair(0, 0)); iterativeDeepeningSearch(source, goal); system("pause"); return 0; }
-
tai dėl to kad tavo funkcija grąžina:
vector < pair < int, pair<int, int> > >
tipą, o priskiri juk
vector< tuple<bool, size_t, size_t> >
tipui
Pasikeisčiau dėl funkcijos, visteik yra klaidų :unsure:
-
-
Kūriau savo programavimą, dėl problemos:
vector< tuple<bool, size_t, size_t> > leafs = newStatesSet(source); for (auto &leaf : leafs) if (validState(leaf)) { if (depthLimitedSearch(leaf, goal, depth - 1, ans)) { ans.push_back(leaf); return true;
Gal dėl to tulpe<>, atrodo taip netinka?
Reikėtų, ar ne:
vector <pair<int, pair<int,int> > > leafs = newStatesSet(source); for(int i=0; i<leafs.size(); i++) if(validState(leafs[i])) { if(depthLimitedSearch(leafs[i], goal, depth-1, ans)){ ans.push_back(leafs[i]); return true; } } }
Lauksiu jūsų patarimo :)
#include <string> #include <utility> #include <vector> #include <iostream> using namespace std; vector < pair < int, pair<int, int> > > newStatesSet(pair< int, pair < int, int > > state) { vector < pair< int, pair< int, int> > > newStatesSet; int C = state.second.first, M = state.second.second; if (state.first == 0) { if (C >= 1) newStatesSet.push_back(make_pair(1, make_pair(C - 1, M))); if (M >= 1) newStatesSet.push_back(make_pair(1, make_pair(C, M - 1))); else if (C >= 2) newStatesSet.push_back(make_pair(1, make_pair(C - 2, M))); if (C >= 1 && M >= 1) newStatesSet.push_back(make_pair(1, make_pair(C - 1, M - 1))); else if (M >= 2) newStatesSet.push_back(make_pair(1, make_pair(C, M - 2))); } else { C = 3 - C; M = 3 - M; if (C >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 1, 3 - M))); if (M >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C, 3 - M + 1))); else if (C >= 2) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 2, 3 - M))); if (C >= 1 && M >= 1) newStatesSet.push_back(make_pair(0, make_pair(3 - C + 1, 3 - M + 1))); else if (M >= 2) newStatesSet.push_back(make_pair(0, make_pair(3 - C, 3 - M + 2))); } return newStatesSet; } bool validState(pair<int, pair<int, int> > state) { int C = state.second.first, M = state.second.second; if (C > M && M != 0) return false; C = 3 - C, M = 3 - M; if (C > M && M != 0) return false; return true; } bool depthLimitedSearch(pair<int, pair<int, int> > source, pair<int, pair<int, int> > goal, int depth, vector<pair<int, pair<int, int> > > &ans) { if (source == goal) return true; if (depth <= 0) return false; vector< tuple<bool, size_t, size_t> > leafs = newStatesSet(source); for (auto &leaf : leafs) if (validState(leaf)) { if (depthLimitedSearch(leaf, goal, depth - 1, ans)) { ans.push_back(leaf); return true; } } } string form(int stateNos, string character) { string rep = ""; for (int i = 1; i <= 3; i++) if (stateNos >= i) rep.append(character); else rep.append(" "); return rep; } void displayState(pair<int, pair<int, int> > state) { string rep = ""; rep.append(form(state.second.first, "C")); rep.append(form(state.second.second, "M")); for (int i = 1; i <= 6; i++) { if (state.first == 0 && i == 2) rep.append("B"); else if (state.first == 1 && i == 5) rep.append("B"); else rep.append(" "); } rep.append(form(3 - state.second.first, "C")); rep.append(form(3 - state.second.second, "M")); cout << rep << endl; } void iterativeDeepeningSearch(pair<int, pair<int, int> > source, pair<int, pair<int, int> > goal) { vector< pair<int, pair<int, int> > > ans; for (int i = 1; i <= 25; i++) { vector<pair<int, pair<int, int> > >vec; depthLimitedSearch(source, goal, i, vec); if (vec.size()>0) { ans = vec; break; } } cout << "C ir M reiškia kanibalus ir misionierius \ n, o B - valties vietą\n"; displayState(source); for (auto it = ans.rbegin(); it != ans.rend(); ++it) displayState(*it); } int main() { pair<int, pair<int, int> > source = make_pair(0, make_pair(3, 3)); pair<int, pair<int, int> > goal = make_pair(1, make_pair(0, 0)); iterativeDeepeningSearch(source, goal); system("pause"); return 0; }
-
-
Programavau apie apskaiciuojama, tai neimanoma. Kaip visada rodyti nulis. Kaip programuos? Gal pades?
#include<iostream> #include <stdio.h> using namespace std; int main() { char str[1000]; int countAlphabet, countDigits, countSpecials, countSpaces, countChooselettera, countChooseletterA; int counter, total, n, total1; //priskirti visus nuliui countAlphabet, countDigits, countSpecials, countSpaces, countChooselettera = 0; printf("Iveskite tekstu:"); gets_s(str); for (counter = 0; str[counter] != NULL; counter++) { if (str[counter] >= '0' && str[counter] <= '9') countDigits++; else if ((str[counter] >= 'A' && str[counter] <= 'Z') || (str[counter] >= 'a' && str[counter] <= 'z')) countAlphabet++; else if (str[counter] == ' ') countSpaces++; else countSpecials++; if (str[counter] == 'a') countChooselettera++; } total = countDigits + countAlphabet + countSpaces + countSpecials; total1 = countChooselettera / total; printf("Alfabetai: %d \n",countAlphabet); printf("Is viso tekstu: %d \n", total); printf("Pasirinkau a raide: %d \n", countChooselettera); printf("apskaiciuojama: %d \n", total1); system("pause"); return 0; }
-
Jeigu gerai suprantu, ką nori padaryti, tai dėl "else if" tau taip nutinka.
if (str[counter] >= '0' && str[counter] <= '9') countDigits++; else if ((str[counter] >= 'A' && str[counter] <= 'Z') || (str[counter] >= 'a' && str[counter] <= 'z')) countAlphabet++; // jeigu čia ateis (o ateis su raidėmis) else if (str[counter] == ' ') countSpaces++; else if ((str[counter] >= 'A') && (str[counter] == 'a')) countChooseletter++; // čia raidės neateis, nes jau if'ą sutiko aukščiau
Iš esmės galima daryti taip:
if (str[counter] >= '0' && str[counter] <= '9') countDigits++; else if ((str[counter] >= 'A' && str[counter] <= 'Z') || (str[counter] >= 'a' && str[counter] <= 'z')) countAlphabet++; else if (str[counter] == ' ') countSpaces++; else countSpecials++; if (str[counter] == 'a') countChooseletter++;
Labai aciu. Jau supratau :)
-
Tureciau butu veikia
printf("Pasirinkau a raide: %d \n", countChooseletter);
, bet rodo ekrane tai 0. Gal kas nors pagalbes?
#include<iostream> #include <stdio.h> using namespace std; int main() { char str[10000]; int countAlphabet, countDigits, countSpecials, countSpaces, countChooseletter; int counter, total; double n; //priskirti visus nuliui countAlphabet, countDigits, countSpecials, countSpaces, countChooseletter = 0; printf("Iveskite tekstu:"); gets_s(str); for (counter = 0; str[counter] != NULL; counter++) { if (str[counter] >= '0' && str[counter] <= '9') countDigits++; else if ((str[counter] >= 'A' && str[counter] <= 'Z') || (str[counter] >= 'a' && str[counter] <= 'z')) countAlphabet++; else if (str[counter] == ' ') countSpaces++; else if ((str[counter] >= 'A') && (str[counter] == 'a')) countChooseletter++; else countSpecials++; } total = countDigits + countAlphabet + countSpaces + countSpecials; printf("Alfabetai: %d \n",countAlphabet); printf("Pasirinkau a raide: %d \n", countChooseletter); printf("Is viso tekstu: %d \n", total); system("pause"); return 0; }
-
Padariau truputį kitaip. Bet dėl dvimačio "bool DP_Matrix[sum + 1][n + 1];", turi buti veikimu. Gal padėsite?
#include <iostream> #include <fstream> #include <algorithm> // std::reverse #include <vector> // std::vector using namespace std; std::vector<unsigned short> getIndecesOfSum( std::vector<unsigned short> numbers, int n, unsigned short sum); int main(int argc, char ** argv) { std::ifstream infile(argv[1]); if (!infile) { std::cout << "could not open " << argv[1]; return 0; } std::ofstream outfile(argv[2]); if (!outfile) { std::cout << "could not open " << argv[2]; return 0; } unsigned short numberOf_testCases; unsigned short credit, numberOf_Items, itemPrice; std::vector<unsigned short> allItems, selectedItems; infile >> numberOf_testCases; for (unsigned int i = 0; i<numberOf_testCases; i++){ infile >> credit; infile >> numberOf_Items; for (unsigned int j = 0; j<numberOf_Items; j++){ infile >> itemPrice; allItems.push_back(itemPrice); } selectedItems = getIndecesOfSum(allItems, allItems.size(), credit); outfile << "Case #" << i + 1 << ": "; for (unsigned int j = 0; j<selectedItems.size(); j++){ outfile << selectedItems[j] << " "; } outfile << endl; allItems.clear(); selectedItems.clear(); } return 0; } std::vector<unsigned short> getIndecesOfSum( std::vector<unsigned short> numbers, int n, unsigned short sum) { std::vector<unsigned short> IndecesOfSum; bool DP_Matrix[sum + 1][n + 1]; for (int i = 0; i <= n; i++) DP_Matrix[0][i] = true; for (int i = 1; i <= sum; i++) DP_Matrix[i][0] = false; for (int i = 1; i <= sum; i++) { for (int j = 1; j <= n; j++) { DP_Matrix[i][j] = DP_Matrix[i][j - 1]; if (i >= numbers[j - 1]) DP_Matrix[i][j] = DP_Matrix[i][j] || DP_Matrix[i - numbers[j - 1]][j - 1]; } } for (int j = n; j >= 1; j--) { if (sum - numbers[j - 1] >= 0 && DP_Matrix[sum - numbers[j - 1]][j - 1]) { IndecesOfSum.push_back(j); sum = sum - numbers[j - 1]; } } std::reverse(IndecesOfSum.begin(), IndecesOfSum.end()); return IndecesOfSum; }
-
Kažkas su tavo projektu negerai, nes man kodas pasileido. Pabandyk susikurti naują Visual Studio projektą ir naujai persikopijuoti kodą.
Buvau pabandyti, tas pats rodo ekrane, ak?
-
Pats programavau, bet rodo ekrane (neveikia). Kodel? Gal isspresim problema?
Programavime
#include <iostream> //For std::vector #include <fstream> //For std::cout and std::cin #include <vector> //For std::vector using namespace std; int main(int argc, char ** argv) { std::ifstream infile(argv[1]); if (!infile) { std::cout << "Could not open " << argv[1]; return 0; } std::ofstream outfile(argv[2]); if (!outfile) { std::cout << "Could not open " << argv[2]; return 0; } unsigned short numberOf_testCases; unsigned short credit, numberOf_Items, itemPrice; std::vector<unsigned short> allItems; infile >> numberOf_testCases; //Bandymų skaičius for (unsigned int i = 0; i<numberOf_testCases; i++){ infile >> credit; //Kreditas infile >> numberOf_Items; //Elementų skaičius for (unsigned int j = 0; j<numberOf_Items; j++){ infile >> itemPrice; allItems.push_back(itemPrice); } bool breakBool = false; for (unsigned int j = 0; j<allItems.size(); j++){ for (unsigned int k = j + 1; k<allItems.size(); k++){ if ((allItems[j] + allItems[k]) == credit) { outfile << "Atvejis: " << i + 1; outfile << ": " << j + 1 << " " << k + 1 << endl; breakBool = true; break; } } if (breakBool) break; } allItems.clear(); } return 0; }
-
Antra eilute tai jau pasidare rezultata. Bet noriu buti su kiekvienais kartu kiek skaiciuoja laiko funkcija(kuri paskutine eilute programavau).
-
Pagalbos dėl PHP ir MySql
Programuotojų kampas
Atrašyta
Pvz. kai klientas nori užsiregistruoti dėl paslaugų. O organizacija (per „admin panel“) turi būti, jei priimta, kurį klientas užsiregistruota. Tada admin turėtų spausti „patvirtinti“, ir automatiškai išsiųsti į el.paštą. Jei admin norėtų atšaukti, tada automatiškai išsiųsti į el. paštą, nebus teikti paslaugą.