From e3c92ee3cae08952e7ae6aed0799aa879cbda0fa Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:07:29 -0300 Subject: [PATCH 01/13] Adiciona gabarito - TP02Q01 --- .../TP02Q01 - Classe Filme em Java/Game.java | 565 ++++++++++++++++++ .../TP02Q01 - Classe Filme em Java/pedro.out | 50 ++ .../TP02Q01 - Classe Filme em Java/pub.in | 51 ++ .../TP02Q01 - Classe Filme em Java/pub.out | 50 ++ 4 files changed, 716 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pedro.out create mode 100644 tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.out diff --git a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java new file mode 100644 index 0000000..55b765d --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java @@ -0,0 +1,565 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + // -------------------------------------------------------------------------------------- // + + public static boolean isFim(String line) { return line.compareTo("FIM") == 0; } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + ArrayList games = new ArrayList(); + + // ------------------------------------------------------------------------------ // + + try { + + // Read CSV file + String basefile = "/tmp/games.csv"; + + FileInputStream fstream = new FileInputStream(basefile); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Explode CSV file reading games + String line; + + while((line = br.readLine()) != null) { + + Game game = new Game(); + + game.read(line); + games.add(game); + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Read .in file + Scanner scr = new Scanner(System.in); + String line = scr.nextLine(); + + while(true) { + + if(isFim(line)) break; + + int app_id = Integer.parseInt(line); + + // Search game with .in id + for(Game game : games) { + + if(game.getAppId() == app_id) game.print(); + } + + line = scr.nextLine(); + } + + // ---------------------------------------------------------------------------------------------- // + + scr.close(); + } + + // ---------------------------------------------------------------------------------------------- // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pedro.out b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pedro.out new file mode 100644 index 0000000..929980c --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pedro.out @@ -0,0 +1,50 @@ +840010 Garden Paws Dec/2018 50000 - 100000 0 19.99 2 [English] http://www.gardenpawsgame.com true true false 92% 5h 46m Bitten Toast Games Inc. [Adventure, Indie, RPG, Simulation] +866510 !AnyWay! Jun/2018 50000 - 100000 0 1.79 37 [English, Russian, French, Italian, German, Polish, Ukrainian, Swedish, Simplified Chinese] null true false false 69% 5h 53m EYEFRONT [Adventure, Casual, Indie] +1970560 Bobbi Adventure May/2022 50000 - 100000 0 24.99 0 [English] null true false false 67% null Felio Stung ROG [Indie] +411740 Yet Another World Nov/2015 50000 - 100000 0 5.99 0 [English] null true true true 78% 6h 24m Energy Milk [Action, Adventure, Indie] +1509590 Fujiwara Bittersweet Jan/2021 50000 - 100000 0 0.00 0 [English] null true true true 91% null MagicBenchVN [Free to Play, Indie] +458520 Wrath of Anna Apr/2018 50000 - 100000 0 19.99 1 [English, Spanish - Spain, Hungarian, German, Norwegian, Polish, Swedish, Russian] http://LorenzoEnt.com true false false 35% 2h 50m Lorenzo Ent.,Michael L. Fiorentino Gutierrez [Action, Adventure, Indie] +920210 LEGO® Star Wars™: The Skywalker Saga Apr/2022 500000 - 1000000 0 49.99 8 [English, French, Italian, German, Spanish - Spain, Arabic, Danish, Dutch, Korean, Polish, Portuguese - Brazil, Russian, Spanish - Latin America, Traditional Chinese, Japanese] null true false false 92% 22h 42m TT Games [Action, Adventure] +1444020 Reactor Tech² Aug/2021 50000 - 100000 0 14.99 0 [English, Russian] null true false false 68% null 4Co [Indie, Simulation, Strategy] +1232460 Onee Chanbara ORIGIN Oct/2020 50000 - 100000 18 59.99 96 [English, Simplified Chinese, Traditional Chinese, Japanese, Korean] null true false false 72% 2h 25m Tamsoft [Action] +2026070 Tank Commander: Battlefield Jul/2022 50000 - 100000 0 2.99 0 [English] null true false false 100% null SP GAMES [Action, Indie, Simulation] +258880 Professional Farmer 2014 Nov/2013 50000 - 100000 0 2.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Russian, Dutch, Swedish, Norwegian] http://www.professional-farmer.com/ true false false 46% 32h 9m PlayWay S.A. [Simulation] +295250 Stranded May/2014 50000 - 100000 0 0.49 0 [English] null true true true 35% 3h 56m Peter Moorhead [Adventure, Indie] +299500 International Snooker May/2014 50000 - 100000 0 5.99 0 [English] http://www.bigheadgames.co.uk/ true false false 62% 1h 11m Big Head Games Ltd [Casual, Sports] +574080 Fog of War Jun/2018 50000 - 100000 0 4.99 1 [English, Russian] null true false false 48% 6h 14m Monkeys Lab. [Action, Indie, Massively Multiplayer, RPG, Simulation, Strategy] +598780 Boreal Blade Nov/2020 50000 - 100000 0 3.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese] https://www.borealblade.com true false false 66% null Frozenbyte [Action, Early Access] +1217190 浮世万千之前世今生 Jan/2020 50000 - 100000 0 5.49 1 [Simplified Chinese] null true false false 78% null 飞天大胖喵 [Adventure, Casual, Indie, RPG, Strategy] +257730 Infinity Wars: Animated Trading Card Game Sep/2014 500000 - 1000000 0 0.00 0 [English, Simplified Chinese] http://www.infinitywarsgame.com true false false 77% 6h 24m Lightmare Studios [Indie, Massively Multiplayer, Strategy] +1807730 Lab Bio-Terror Dec/2021 50000 - 100000 0 12.99 0 [English] null true false false 82% null VOLTECH [Action, Indie] +773670 Delete Jan/2018 50000 - 100000 0 1.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean] null true true false 96% 1h 24m PONY [Casual, Indie] +1803150 Void Slayer Jan/2022 50000 - 100000 0 4.99 0 [English] null true false false 79% null Madmind Studio: After hours [Action, Indie] +1573070 Endless Furry Blackjack Mar/2021 50000 - 100000 0 0.99 0 [English] https://m.youtube.com/ericyoungvfx/ true false false 20% null Tegridy Made Games [Casual, Indie, Sports, Strategy] +513930 J.U.R : Japan Underground Racing Aug/2016 50000 - 100000 0 0.49 0 [English] null true false false 32% null JDM4iK [Casual, Indie, Racing, Simulation] +385250 Paint it Back Oct/2015 50000 - 100000 0 7.99 0 [English] http://casuallabs.com/wp/?page_id=24 true true true 98% null Casual Labs [Casual] +261880 Corporate Lifestyle Simulator Mar/2014 50000 - 100000 0 4.99 1 [English] http://www.dolphinbarn.com true false false 83% 4h 7m DolphinBarn [Action, Casual, Indie] +533300 Zup! Oct/2016 500000 - 1000000 0 0.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Portuguese - Brazil, Hungarian, Greek, Danish, Traditional Chinese, Simplified Chinese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Thai, Turkish, Ukrainian, Finnish, Czech, Swedish, Japanese] http://quietriver.info/ true false false 94% 1h 42m Quiet River [Casual, Indie] +542340 Slingshot people Oct/2016 500000 - 1000000 0 0.99 0 [English] http://www.vsemagy.ru/index.php true false false 47% 3h 50m StalkerAlex [Action, Casual, Indie, Simulation] +1209040 Cyber Hunter Jun/2020 500000 - 1000000 0 0.00 0 [English, French, German, Spanish - Spain, Russian, Japanese, Simplified Chinese, Traditional Chinese, Portuguese - Brazil, Korean, Thai, Vietnamese] https://www.cyberhunter.game/ true false false 73% 5h 41m NetEase Games [Action, Free to Play, Massively Multiplayer] +8790 GTR 2 FIA GT Racing Game Dec/2012 50000 - 100000 0 7.99 0 [English] http://www.simbin.com/games/gtr2/ true false false 93% 11m SimBin Studios AB [Racing, Simulation, Sports] +8000 Tomb Raider: Anniversary Jun/2007 500000 - 1000000 13 8.99 0 [English, French, German, Italian, Spanish - Spain] http://www.tombraider.com/anniversary/ true false false 82% 6h Crystal Dynamics [Action, Adventure] +415150 Pang Adventures Apr/2016 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Portuguese - Brazil, Russian] https://www.facebook.com/Pang.Adventures/ true false false 80% 3h 29m Dotemu [Action, Casual, Strategy] +2012500 The Katydids Incident Jun/2022 50000 - 100000 0 4.99 0 [English] https://punxstudios.co true false false 100% null Punx Studios [Indie, Simulation] +691150 Saku Saku: Love Blooms with the Cherry Blossoms Oct/2017 50000 - 100000 0 19.99 0 [English] null true false false 92% 5h 16m PALETTE [Sexual Content, Nudity, Casual] +283370 Marine Sharpshooter II: Jungle Warfare Apr/2014 50000 - 100000 0 2.99 0 [English] http://www.funboxmedia.co.uk/ true false false 32% 2h 3m Jarhead Games [Action] +249650 Blackguards Jan/2014 500000 - 1000000 0 0.99 2 [English, German, French, Spanish - Spain, Portuguese - Brazil, Russian, Italian, Japanese, Korean, Czech, Turkish, Polish, Simplified Chinese] http://www.blackguards-game.com true false false 62% 8h 58m Daedalic Entertainment [Indie, RPG, Strategy] +268870 Satellite Reign Aug/2015 500000 - 1000000 0 29.99 3 [English, French, Italian, German, Spanish - Spain, Czech, Russian] http://www.satellitereign.com/ true true true 71% 5h 18m 5 Lives Studios [Action, Indie, Strategy] +1172510 Unlock The King Nov/2019 50000 - 100000 0 0.99 0 [English] null true true false 96% null Minimol Games [Casual, Strategy] +927890 Hentai Girl Linda Dec/2018 50000 - 100000 0 0.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean, Spanish - Latin America, Vietnamese] null true true false 94% 1h 13m GirlGames [Casual, Indie, RPG, Simulation] +25700 Madballs in Babo:Invasion Sep/2009 50000 - 100000 0 4.99 7 [English, German, Korean, Portuguese, Spanish - Spain, French, Italian, Russian] http://www.baboinvasion.com true true false 84% 4h 15m Playbrains [Action, Casual, Indie] +281610 Homeworld: Deserts of Kharak Jan/2016 500000 - 1000000 0 49.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Polish] http://www.desertsofkharak.com true true false 83% 8h 32m Blackbird Interactive [Strategy] +485610 Ball 3D: Soccer Online Mar/2017 500000 - 1000000 0 9.99 0 [English] http://www.ball3d.com true true false 83% 2h 49m Unusualsoft [Sports] +1276850 Kane's Shadow Apr/2020 50000 - 100000 0 0.00 0 [English] null true true false 67% null Plush Productions LLC [Casual, Indie] +722340 Captain vs Sky Pirates Oct/2017 50000 - 100000 0 2.99 5 [English] https://store.steampowered.com/publisher/boogygames/ true false false 25% null Boogygames Studios [Action, Adventure, Indie, Strategy] +1499640 Y.E.T.I Jan/2021 50000 - 100000 0 0.49 0 [English] https://anpa.us true false false 80% null Racing Bros [Action, Indie] +1848450 Nightmare of Decay May/2022 50000 - 100000 0 3.99 0 [English, French, Polish, Russian, Simplified Chinese, Traditional Chinese, Spanish - Latin America, Portuguese - Brazil, Italian, German, Czech, Hungarian, Turkish, Norwegian, Swedish] null true false false 98% 5h 56m Checkmaty [Action, Adventure, Indie] +615700 A Plunge into Darkness Mar/2020 50000 - 100000 0 5.99 1 [English] https://www.aldorlea.org/ true false false 73% null Aldorlea [Adventure, Indie, RPG, Simulation, Strategy] +744980 Super Club Soccer Oct/2019 50000 - 100000 0 0.00 0 [English] http://www.superclubsoccer.com/ true false true 69% null Trick27 Studios Limited [Free to Play, Massively Multiplayer, Sports, Early Access] +10180 Call of Duty®: Modern Warfare® 2 (2009) Nov/2009 5000000 - 10000000 0 19.99 2 [English, French, German, Italian, Spanish - Spain] https://www.callofduty.com/ true true false 93% 12h 56m Infinity Ward [Action] +234390 Teleglitch: Die More Edition Jul/2013 500000 - 1000000 0 3.24 1 [English] http://www.teleglitch.com true true true 85% 2h 20m Test3 Projects [Action, Indie] +1641670 EdgeOfTheAbyssAwaken Jun/2022 50000 - 100000 0 18.99 3 [English, Simplified Chinese] null true false false 74% null TrinityBJ [Action, Indie, RPG, Strategy] +427520 Factorio Aug/2020 5000000 - 10000000 0 30.00 1 [English, French, Italian, German, Spanish - Spain, Hungarian, Dutch, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Finnish, Swedish, Czech, Russian, Ukrainian, Japanese, Simplified Chinese, Traditional Chinese, Korean, Turkish] https://www.factorio.com true true true 97% 89h 43m Wube Software LTD. [Casual, Indie, Simulation, Strategy] diff --git a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.in b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.in new file mode 100644 index 0000000..cf004e0 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.in @@ -0,0 +1,51 @@ +840010 +866510 +1970560 +411740 +1509590 +458520 +920210 +1444020 +1232460 +2026070 +258880 +295250 +299500 +574080 +598780 +1217190 +257730 +1807730 +773670 +1803150 +1573070 +513930 +385250 +261880 +533300 +542340 +1209040 +8790 +8000 +415150 +2012500 +691150 +283370 +249650 +268870 +1172510 +927890 +25700 +281610 +485610 +1276850 +722340 +1499640 +1848450 +615700 +744980 +10180 +234390 +1641670 +427520 +FIM diff --git a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.out b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.out new file mode 100644 index 0000000..929980c --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/pub.out @@ -0,0 +1,50 @@ +840010 Garden Paws Dec/2018 50000 - 100000 0 19.99 2 [English] http://www.gardenpawsgame.com true true false 92% 5h 46m Bitten Toast Games Inc. [Adventure, Indie, RPG, Simulation] +866510 !AnyWay! Jun/2018 50000 - 100000 0 1.79 37 [English, Russian, French, Italian, German, Polish, Ukrainian, Swedish, Simplified Chinese] null true false false 69% 5h 53m EYEFRONT [Adventure, Casual, Indie] +1970560 Bobbi Adventure May/2022 50000 - 100000 0 24.99 0 [English] null true false false 67% null Felio Stung ROG [Indie] +411740 Yet Another World Nov/2015 50000 - 100000 0 5.99 0 [English] null true true true 78% 6h 24m Energy Milk [Action, Adventure, Indie] +1509590 Fujiwara Bittersweet Jan/2021 50000 - 100000 0 0.00 0 [English] null true true true 91% null MagicBenchVN [Free to Play, Indie] +458520 Wrath of Anna Apr/2018 50000 - 100000 0 19.99 1 [English, Spanish - Spain, Hungarian, German, Norwegian, Polish, Swedish, Russian] http://LorenzoEnt.com true false false 35% 2h 50m Lorenzo Ent.,Michael L. Fiorentino Gutierrez [Action, Adventure, Indie] +920210 LEGO® Star Wars™: The Skywalker Saga Apr/2022 500000 - 1000000 0 49.99 8 [English, French, Italian, German, Spanish - Spain, Arabic, Danish, Dutch, Korean, Polish, Portuguese - Brazil, Russian, Spanish - Latin America, Traditional Chinese, Japanese] null true false false 92% 22h 42m TT Games [Action, Adventure] +1444020 Reactor Tech² Aug/2021 50000 - 100000 0 14.99 0 [English, Russian] null true false false 68% null 4Co [Indie, Simulation, Strategy] +1232460 Onee Chanbara ORIGIN Oct/2020 50000 - 100000 18 59.99 96 [English, Simplified Chinese, Traditional Chinese, Japanese, Korean] null true false false 72% 2h 25m Tamsoft [Action] +2026070 Tank Commander: Battlefield Jul/2022 50000 - 100000 0 2.99 0 [English] null true false false 100% null SP GAMES [Action, Indie, Simulation] +258880 Professional Farmer 2014 Nov/2013 50000 - 100000 0 2.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Russian, Dutch, Swedish, Norwegian] http://www.professional-farmer.com/ true false false 46% 32h 9m PlayWay S.A. [Simulation] +295250 Stranded May/2014 50000 - 100000 0 0.49 0 [English] null true true true 35% 3h 56m Peter Moorhead [Adventure, Indie] +299500 International Snooker May/2014 50000 - 100000 0 5.99 0 [English] http://www.bigheadgames.co.uk/ true false false 62% 1h 11m Big Head Games Ltd [Casual, Sports] +574080 Fog of War Jun/2018 50000 - 100000 0 4.99 1 [English, Russian] null true false false 48% 6h 14m Monkeys Lab. [Action, Indie, Massively Multiplayer, RPG, Simulation, Strategy] +598780 Boreal Blade Nov/2020 50000 - 100000 0 3.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese] https://www.borealblade.com true false false 66% null Frozenbyte [Action, Early Access] +1217190 浮世万千之前世今生 Jan/2020 50000 - 100000 0 5.49 1 [Simplified Chinese] null true false false 78% null 飞天大胖喵 [Adventure, Casual, Indie, RPG, Strategy] +257730 Infinity Wars: Animated Trading Card Game Sep/2014 500000 - 1000000 0 0.00 0 [English, Simplified Chinese] http://www.infinitywarsgame.com true false false 77% 6h 24m Lightmare Studios [Indie, Massively Multiplayer, Strategy] +1807730 Lab Bio-Terror Dec/2021 50000 - 100000 0 12.99 0 [English] null true false false 82% null VOLTECH [Action, Indie] +773670 Delete Jan/2018 50000 - 100000 0 1.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean] null true true false 96% 1h 24m PONY [Casual, Indie] +1803150 Void Slayer Jan/2022 50000 - 100000 0 4.99 0 [English] null true false false 79% null Madmind Studio: After hours [Action, Indie] +1573070 Endless Furry Blackjack Mar/2021 50000 - 100000 0 0.99 0 [English] https://m.youtube.com/ericyoungvfx/ true false false 20% null Tegridy Made Games [Casual, Indie, Sports, Strategy] +513930 J.U.R : Japan Underground Racing Aug/2016 50000 - 100000 0 0.49 0 [English] null true false false 32% null JDM4iK [Casual, Indie, Racing, Simulation] +385250 Paint it Back Oct/2015 50000 - 100000 0 7.99 0 [English] http://casuallabs.com/wp/?page_id=24 true true true 98% null Casual Labs [Casual] +261880 Corporate Lifestyle Simulator Mar/2014 50000 - 100000 0 4.99 1 [English] http://www.dolphinbarn.com true false false 83% 4h 7m DolphinBarn [Action, Casual, Indie] +533300 Zup! Oct/2016 500000 - 1000000 0 0.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Portuguese - Brazil, Hungarian, Greek, Danish, Traditional Chinese, Simplified Chinese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Thai, Turkish, Ukrainian, Finnish, Czech, Swedish, Japanese] http://quietriver.info/ true false false 94% 1h 42m Quiet River [Casual, Indie] +542340 Slingshot people Oct/2016 500000 - 1000000 0 0.99 0 [English] http://www.vsemagy.ru/index.php true false false 47% 3h 50m StalkerAlex [Action, Casual, Indie, Simulation] +1209040 Cyber Hunter Jun/2020 500000 - 1000000 0 0.00 0 [English, French, German, Spanish - Spain, Russian, Japanese, Simplified Chinese, Traditional Chinese, Portuguese - Brazil, Korean, Thai, Vietnamese] https://www.cyberhunter.game/ true false false 73% 5h 41m NetEase Games [Action, Free to Play, Massively Multiplayer] +8790 GTR 2 FIA GT Racing Game Dec/2012 50000 - 100000 0 7.99 0 [English] http://www.simbin.com/games/gtr2/ true false false 93% 11m SimBin Studios AB [Racing, Simulation, Sports] +8000 Tomb Raider: Anniversary Jun/2007 500000 - 1000000 13 8.99 0 [English, French, German, Italian, Spanish - Spain] http://www.tombraider.com/anniversary/ true false false 82% 6h Crystal Dynamics [Action, Adventure] +415150 Pang Adventures Apr/2016 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Portuguese - Brazil, Russian] https://www.facebook.com/Pang.Adventures/ true false false 80% 3h 29m Dotemu [Action, Casual, Strategy] +2012500 The Katydids Incident Jun/2022 50000 - 100000 0 4.99 0 [English] https://punxstudios.co true false false 100% null Punx Studios [Indie, Simulation] +691150 Saku Saku: Love Blooms with the Cherry Blossoms Oct/2017 50000 - 100000 0 19.99 0 [English] null true false false 92% 5h 16m PALETTE [Sexual Content, Nudity, Casual] +283370 Marine Sharpshooter II: Jungle Warfare Apr/2014 50000 - 100000 0 2.99 0 [English] http://www.funboxmedia.co.uk/ true false false 32% 2h 3m Jarhead Games [Action] +249650 Blackguards Jan/2014 500000 - 1000000 0 0.99 2 [English, German, French, Spanish - Spain, Portuguese - Brazil, Russian, Italian, Japanese, Korean, Czech, Turkish, Polish, Simplified Chinese] http://www.blackguards-game.com true false false 62% 8h 58m Daedalic Entertainment [Indie, RPG, Strategy] +268870 Satellite Reign Aug/2015 500000 - 1000000 0 29.99 3 [English, French, Italian, German, Spanish - Spain, Czech, Russian] http://www.satellitereign.com/ true true true 71% 5h 18m 5 Lives Studios [Action, Indie, Strategy] +1172510 Unlock The King Nov/2019 50000 - 100000 0 0.99 0 [English] null true true false 96% null Minimol Games [Casual, Strategy] +927890 Hentai Girl Linda Dec/2018 50000 - 100000 0 0.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean, Spanish - Latin America, Vietnamese] null true true false 94% 1h 13m GirlGames [Casual, Indie, RPG, Simulation] +25700 Madballs in Babo:Invasion Sep/2009 50000 - 100000 0 4.99 7 [English, German, Korean, Portuguese, Spanish - Spain, French, Italian, Russian] http://www.baboinvasion.com true true false 84% 4h 15m Playbrains [Action, Casual, Indie] +281610 Homeworld: Deserts of Kharak Jan/2016 500000 - 1000000 0 49.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Polish] http://www.desertsofkharak.com true true false 83% 8h 32m Blackbird Interactive [Strategy] +485610 Ball 3D: Soccer Online Mar/2017 500000 - 1000000 0 9.99 0 [English] http://www.ball3d.com true true false 83% 2h 49m Unusualsoft [Sports] +1276850 Kane's Shadow Apr/2020 50000 - 100000 0 0.00 0 [English] null true true false 67% null Plush Productions LLC [Casual, Indie] +722340 Captain vs Sky Pirates Oct/2017 50000 - 100000 0 2.99 5 [English] https://store.steampowered.com/publisher/boogygames/ true false false 25% null Boogygames Studios [Action, Adventure, Indie, Strategy] +1499640 Y.E.T.I Jan/2021 50000 - 100000 0 0.49 0 [English] https://anpa.us true false false 80% null Racing Bros [Action, Indie] +1848450 Nightmare of Decay May/2022 50000 - 100000 0 3.99 0 [English, French, Polish, Russian, Simplified Chinese, Traditional Chinese, Spanish - Latin America, Portuguese - Brazil, Italian, German, Czech, Hungarian, Turkish, Norwegian, Swedish] null true false false 98% 5h 56m Checkmaty [Action, Adventure, Indie] +615700 A Plunge into Darkness Mar/2020 50000 - 100000 0 5.99 1 [English] https://www.aldorlea.org/ true false false 73% null Aldorlea [Adventure, Indie, RPG, Simulation, Strategy] +744980 Super Club Soccer Oct/2019 50000 - 100000 0 0.00 0 [English] http://www.superclubsoccer.com/ true false true 69% null Trick27 Studios Limited [Free to Play, Massively Multiplayer, Sports, Early Access] +10180 Call of Duty®: Modern Warfare® 2 (2009) Nov/2009 5000000 - 10000000 0 19.99 2 [English, French, German, Italian, Spanish - Spain] https://www.callofduty.com/ true true false 93% 12h 56m Infinity Ward [Action] +234390 Teleglitch: Die More Edition Jul/2013 500000 - 1000000 0 3.24 1 [English] http://www.teleglitch.com true true true 85% 2h 20m Test3 Projects [Action, Indie] +1641670 EdgeOfTheAbyssAwaken Jun/2022 50000 - 100000 0 18.99 3 [English, Simplified Chinese] null true false false 74% null TrinityBJ [Action, Indie, RPG, Strategy] +427520 Factorio Aug/2020 5000000 - 10000000 0 30.00 1 [English, French, Italian, German, Spanish - Spain, Hungarian, Dutch, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Finnish, Swedish, Czech, Russian, Ukrainian, Japanese, Simplified Chinese, Traditional Chinese, Korean, Turkish] https://www.factorio.com true true true 97% 89h 43m Wube Software LTD. [Casual, Indie, Simulation, Strategy] From 696f82e18db271bd0b6a988190ede00bbab55d89 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:08:18 -0300 Subject: [PATCH 02/13] Adiciona gabarito - TP02Q02 --- .../tp02/TP02Q02 - Registro em C/Linux_Game | Bin 0 -> 25888 bytes .../tp02/TP02Q02 - Registro em C/Linux_Game.c | 718 ++++++++++++++++++ .../tp02/TP02Q02 - Registro em C/WSL_Game | Bin 0 -> 25888 bytes .../tp02/TP02Q02 - Registro em C/WSL_Game.c | 718 ++++++++++++++++++ .../tp02/TP02Q02 - Registro em C/pedro.out | 50 ++ .../tp02/TP02Q02 - Registro em C/pub.in | 51 ++ .../tp02/TP02Q02 - Registro em C/pub.out | 50 ++ 7 files changed, 1587 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/pedro.out create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.out diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game new file mode 100644 index 0000000000000000000000000000000000000000..2170b62341e052fcd2501a651f5f22dcb64a015b GIT binary patch literal 25888 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 H4Q2laa(ZD_ literal 0 HcmV?d00001 diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c new file mode 100644 index 0000000..575f5ac --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c @@ -0,0 +1,718 @@ +// -------------------------------------------------------------------------------- // + +// Includes +#include +#include +#include +#include +#include + +// -------------------------------------------------------------------------------- // + +// Definitions +#define MAX_GAMES 9000 +#define MAX_FIELD_SIZE 250 +#define MAX_STRING_ARRAY_SIZE 100 + +// -------------------------------------------------------------------------------- // + +// Structs +typedef struct { + + int year, + month; +} Date; + +typedef struct { + + char name[MAX_FIELD_SIZE], + owners[MAX_FIELD_SIZE], + website[MAX_FIELD_SIZE], + developers[MAX_FIELD_SIZE], + languages[MAX_STRING_ARRAY_SIZE][30], + genres[MAX_STRING_ARRAY_SIZE][30]; + + Date release_date; + int app_id, age, dlcs, avg_playtime, count_languages, count_genres; + float price, upvotes; + bool windows_os, mac_os, linux_os; + +} Game; + +// -------------------------------------------------------------------------------- // + +// Global variables +Game games[MAX_GAMES]; +int n = 0; + +// -------------------------------------------------------------------------------- // + +// Functions +bool isFim(char* line) { return line[0] == 'F' && line[1] == 'I' && line[2] == 'M'; } + +void substring(char *string, char *string_start, int length) { + + strncpy(string, string_start, length); + string[length] = '\0'; +} + +char *getMonthName(int month) { + + switch(month) { + + case 1: return "Jan"; break; + case 2: return "Feb"; break; + case 3: return "Mar"; break; + case 4: return "Apr"; break; + case 5: return "May"; break; + case 6: return "Jun"; break; + case 7: return "Jul"; break; + case 8: return "Aug"; break; + case 9: return "Sep"; break; + case 10: return "Oct"; break; + case 11: return "Nov"; break; + case 12: return "Dec"; break; + + default: return "N/A"; break; + } +} + +int getMonthNumber(char* month) { + + if(!strcmp(month, "Jan")) return 1; + else if(!strcmp(month, "Feb")) return 2; + else if(!strcmp(month, "Mar")) return 3; + else if(!strcmp(month, "Apr")) return 4; + else if(!strcmp(month, "May")) return 5; + else if(!strcmp(month, "Jun")) return 6; + else if(!strcmp(month, "Jul")) return 7; + else if(!strcmp(month, "Aug")) return 8; + else if(!strcmp(month, "Sep")) return 9; + else if(!strcmp(month, "Oct")) return 10; + else if(!strcmp(month, "Nov")) return 11; + else if(!strcmp(month, "Dec")) return 12; +} + +// -------------------------------------------------------------------------------- // + +// Class game functions +void game_start(Game *game) { + + strcpy(game -> name, ""); + strcpy(game -> owners, ""); + strcpy(game -> website, ""); + strcpy(game -> developers, ""); + + for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) { + + strcpy(game -> languages[i], ""); + strcpy(game -> genres[i], ""); + } + + game -> release_date.month = -1; + game -> release_date.year = -1; + game -> app_id = -1; + game -> age = -1; + game -> dlcs = -1; + game -> avg_playtime = -1; + game -> price = -1; + game -> upvotes = -1; + game -> windows_os = false; + game -> mac_os = false; + game -> linux_os = false; + + game -> count_languages = 0; + game -> count_genres = 0; +} + +void game_print(Game *game) { + + int hours = game -> avg_playtime / 60, + minutes = game -> avg_playtime % 60; + + printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs); + + for(int i = 0; i < game -> count_languages; i++) { + + printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : ""); + } + + printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false"); + + if(isnan(game -> upvotes)) printf("0.0%% "); + else printf("%.0f%% ", game -> upvotes); + + if(hours > 0) + { + printf("%ih ", hours); + + if(minutes > 0) printf("%im ", minutes); + } + else { + + if(minutes > 0) printf("%im ", minutes); + else printf("null "); + } + + printf("%s [", game -> developers); + + for(int i = 0; i < game -> count_genres; i++) { + + printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : ""); + } + + printf("]\n"); +} + +Game game_clone(Game *game) { + + Game cloned; + + strcpy(cloned.name, game -> name); + strcpy(cloned.owners, game -> owners); + strcpy(cloned.website, game -> website); + strcpy(cloned.developers, game -> developers); + + for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]); + for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]); + + cloned.release_date.month = game -> release_date.month; + cloned.release_date.year = game -> release_date.year; + cloned.app_id = game -> app_id; + cloned.age = game -> age; + cloned.dlcs = game -> dlcs; + cloned.avg_playtime = game -> avg_playtime; + cloned.price = game -> price; + cloned.upvotes = game -> upvotes; + cloned.windows_os = game -> windows_os; + cloned.mac_os = game -> mac_os; + cloned.linux_os = game -> linux_os; + return cloned; +} + +void game_read(Game *game, char *line) { + + char c_search, sub[MAX_FIELD_SIZE]; + int index = 0, atr_index = 0; + + // ------------------------------------------------------------ // + + // Find "AppID" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> app_id = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Name" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> name, sub); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else { + + strcpy(game -> name, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find release date + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + + char subDate[10]; + + substring(subDate, &sub[0], 3); + + game -> release_date.month = getMonthNumber(subDate); + + if(c_search == ',') { + + substring(subDate, &sub[4], 4); + + game -> release_date.year = atoi(subDate); + + index++; + } + else if(c_search == '\"') { + + int nmbSpace = 0; + + for(int i = 0; ; i++) { + + if(sub[i] == ' ') nmbSpace++; + + if(nmbSpace == 2) { + + i++; + + substring(subDate, &sub[i], 4); + + game -> release_date.year = atoi(subDate); + break; + } + } + + index += 2; + } + + atr_index = index; + break; + } + } + } + else { + + game -> release_date.month = 0; + game -> release_date.year = 0; + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Owners" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> owners, sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Age" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> age = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Price" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> price = atof(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "DLCs" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> dlcs = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Languages" + while(true) { + + index++; + + if(line[index] == ']') { + + index++; + + if(line[index] == ',') index++; + else if(line[index] == '\"') index += 2; + + atr_index = index; + break; + } + else if(line[index] == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line[index] == '\'') { + + substring(sub, &line[wordStart], index - wordStart); + strcpy(game -> languages[game -> count_languages++], sub); + break; + } + } + } + } + + // ------------------------------------------------------------ // + + // Find "Website" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> website, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> website, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Windows" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> windows_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> mac_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> linux_os = true; + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + positives = atoi(sub); + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + negatives = atoi(sub); + atr_index = ++index; + break; + } + } + + game -> upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ------------------------------------------------------------ // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> avg_playtime = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Developers" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> developers, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> developers, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Genres" + if(index < strlen(line) - 1) { + + if(line[index] == ',') atr_index = ++index; + + if(line[atr_index] == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> genres[game -> count_genres++], sub); + + atr_index = ++index; + } + else if(line[index] == '\"') { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + if(sub[strlen(sub) - 1] == '\"') sub[strlen(sub) - 1] = '\0'; + else if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0'; + + strcpy(game -> genres[game -> count_genres++], sub); + break; + } + } + } + else { + + substring(sub, &line[atr_index], strlen(line) - 2 - atr_index); + + strcpy(game -> genres[game -> count_genres++], sub); + } + } +} + +// -------------------------------------------------------------------------------- // + +// Functions - List +void list_insert(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + games[n++] = x; +} + +// ---------------------------------------------------------------------------------------------------------- // + +int main() { + + // ------------------------------------------------------------ // + + // First part - Read all games + + // Open CSV file + FILE *fp; + char *line = NULL; + size_t len = 0; + size_t read; + + fp = fopen("/tmp/games.csv", "r"); + + if(fp == NULL) exit(EXIT_FAILURE); + + // ------------------------- // + + // Fill games list + while((read = getline(&line, &len, fp)) != -1) { + + Game game; + + game_start(&game); + game_read(&game, line); + list_insert(game); + } + + // ------------------------- // + + fclose(fp); + + if(line) free(line); + + // ------------------------------------------------------------ // + + // Second part - Print .in games + + char in[15]; + scanf(" %[^\n]s", in); + + while(true) { + + if(isFim(in)) break; + else { + + int app_id = atoi(in); + + for(int i = 0; i < n; i++) { + + if(games[i].app_id == app_id) { + + game_print(&games[i]); + break; + } + } + + // ------------------------- // + + scanf(" %[^\n]s", in); + } + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game b/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game new file mode 100644 index 0000000000000000000000000000000000000000..1186c69a5dc750ce1f7b71537d65fdc0662e76df GIT binary patch literal 25888 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 literal 0 HcmV?d00001 diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c b/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c new file mode 100644 index 0000000..6bba16e --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c @@ -0,0 +1,718 @@ +// -------------------------------------------------------------------------------- // + +// Includes +#include +#include +#include +#include +#include + +// -------------------------------------------------------------------------------- // + +// Definitions +#define MAX_GAMES 9000 +#define MAX_FIELD_SIZE 250 +#define MAX_STRING_ARRAY_SIZE 100 + +// -------------------------------------------------------------------------------- // + +// Structs +typedef struct { + + int year, + month; +} Date; + +typedef struct { + + char name[MAX_FIELD_SIZE], + owners[MAX_FIELD_SIZE], + website[MAX_FIELD_SIZE], + developers[MAX_FIELD_SIZE], + languages[MAX_STRING_ARRAY_SIZE][30], + genres[MAX_STRING_ARRAY_SIZE][30]; + + Date release_date; + int app_id, age, dlcs, avg_playtime, count_languages, count_genres; + float price, upvotes; + bool windows_os, mac_os, linux_os; + +} Game; + +// -------------------------------------------------------------------------------- // + +// Global variables +Game games[MAX_GAMES]; +int n = 0; + +// -------------------------------------------------------------------------------- // + +// Functions +bool isFim(char* line) { return line[0] == 'F' && line[1] == 'I' && line[2] == 'M'; } + +void substring(char *string, char *string_start, int length) { + + strncpy(string, string_start, length); + string[length] = '\0'; +} + +char *getMonthName(int month) { + + switch(month) { + + case 1: return "Jan"; break; + case 2: return "Feb"; break; + case 3: return "Mar"; break; + case 4: return "Apr"; break; + case 5: return "May"; break; + case 6: return "Jun"; break; + case 7: return "Jul"; break; + case 8: return "Aug"; break; + case 9: return "Sep"; break; + case 10: return "Oct"; break; + case 11: return "Nov"; break; + case 12: return "Dec"; break; + + default: return "N/A"; break; + } +} + +int getMonthNumber(char* month) { + + if(!strcmp(month, "Jan")) return 1; + else if(!strcmp(month, "Feb")) return 2; + else if(!strcmp(month, "Mar")) return 3; + else if(!strcmp(month, "Apr")) return 4; + else if(!strcmp(month, "May")) return 5; + else if(!strcmp(month, "Jun")) return 6; + else if(!strcmp(month, "Jul")) return 7; + else if(!strcmp(month, "Aug")) return 8; + else if(!strcmp(month, "Sep")) return 9; + else if(!strcmp(month, "Oct")) return 10; + else if(!strcmp(month, "Nov")) return 11; + else if(!strcmp(month, "Dec")) return 12; +} + +// -------------------------------------------------------------------------------- // + +// Class game functions +void game_start(Game *game) { + + strcpy(game -> name, ""); + strcpy(game -> owners, ""); + strcpy(game -> website, ""); + strcpy(game -> developers, ""); + + for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) { + + strcpy(game -> languages[i], ""); + strcpy(game -> genres[i], ""); + } + + game -> release_date.month = -1; + game -> release_date.year = -1; + game -> app_id = -1; + game -> age = -1; + game -> dlcs = -1; + game -> avg_playtime = -1; + game -> price = -1; + game -> upvotes = -1; + game -> windows_os = false; + game -> mac_os = false; + game -> linux_os = false; + + game -> count_languages = 0; + game -> count_genres = 0; +} + +void game_print(Game *game) { + + int hours = game -> avg_playtime / 60, + minutes = game -> avg_playtime % 60; + + printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs); + + for(int i = 0; i < game -> count_languages; i++) { + + printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : ""); + } + + printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false"); + + if(isnan(game -> upvotes)) printf("0.0%% "); + else printf("%.0f%% ", game -> upvotes); + + if(hours > 0) + { + printf("%ih ", hours); + + if(minutes > 0) printf("%im ", minutes); + } + else { + + if(minutes > 0) printf("%im ", minutes); + else printf("null "); + } + + printf("%s [", game -> developers); + + for(int i = 0; i < game -> count_genres; i++) { + + printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : ""); + } + + printf("]\n"); +} + +Game game_clone(Game *game) { + + Game cloned; + + strcpy(cloned.name, game -> name); + strcpy(cloned.owners, game -> owners); + strcpy(cloned.website, game -> website); + strcpy(cloned.developers, game -> developers); + + for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]); + for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]); + + cloned.release_date.month = game -> release_date.month; + cloned.release_date.year = game -> release_date.year; + cloned.app_id = game -> app_id; + cloned.age = game -> age; + cloned.dlcs = game -> dlcs; + cloned.avg_playtime = game -> avg_playtime; + cloned.price = game -> price; + cloned.upvotes = game -> upvotes; + cloned.windows_os = game -> windows_os; + cloned.mac_os = game -> mac_os; + cloned.linux_os = game -> linux_os; + return cloned; +} + +void game_read(Game *game, char *line) { + + char c_search, sub[MAX_FIELD_SIZE]; + int index = 0, atr_index = 0; + + // ------------------------------------------------------------ // + + // Find "AppID" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> app_id = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Name" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> name, sub); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else { + + strcpy(game -> name, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find release date + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + + char subDate[10]; + + substring(subDate, &sub[0], 3); + + game -> release_date.month = getMonthNumber(subDate); + + if(c_search == ',') { + + substring(subDate, &sub[4], 4); + + game -> release_date.year = atoi(subDate); + + index++; + } + else if(c_search == '\"') { + + int nmbSpace = 0; + + for(int i = 0; ; i++) { + + if(sub[i] == ' ') nmbSpace++; + + if(nmbSpace == 2) { + + i++; + + substring(subDate, &sub[i], 4); + + game -> release_date.year = atoi(subDate); + break; + } + } + + index += 2; + } + + atr_index = index; + break; + } + } + } + else { + + game -> release_date.month = 0; + game -> release_date.year = 0; + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Owners" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> owners, sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Age" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> age = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Price" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> price = atof(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "DLCs" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> dlcs = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Languages" + while(true) { + + index++; + + if(line[index] == ']') { + + index++; + + if(line[index] == ',') index++; + else if(line[index] == '\"') index += 2; + + atr_index = index; + break; + } + else if(line[index] == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line[index] == '\'') { + + substring(sub, &line[wordStart], index - wordStart); + strcpy(game -> languages[game -> count_languages++], sub); + break; + } + } + } + } + + // ------------------------------------------------------------ // + + // Find "Website" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> website, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> website, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Windows" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> windows_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> mac_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> linux_os = true; + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + positives = atoi(sub); + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + negatives = atoi(sub); + atr_index = ++index; + break; + } + } + + game -> upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ------------------------------------------------------------ // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> avg_playtime = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Developers" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> developers, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> developers, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Genres" + if(index < strlen(line) - 1) { + + if(line[index] == ',') atr_index = ++index; + + if(line[atr_index] == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> genres[game -> count_genres++], sub); + + atr_index = ++index; + } + else if(line[index] == '\"') { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + if(sub[strlen(sub) - 1] == '\"') sub[strlen(sub) - 1] = '\0'; + else if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0'; + + strcpy(game -> genres[game -> count_genres++], sub); + break; + } + } + } + else { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + strcpy(game -> genres[game -> count_genres++], sub); + } + } +} + +// -------------------------------------------------------------------------------- // + +// Functions - List +void list_insert(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + games[n++] = x; +} + +// ---------------------------------------------------------------------------------------------------------- // + +int main() { + + // ------------------------------------------------------------ // + + // First part - Read all games + + // Open CSV file + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + + fp = fopen("/tmp/games.csv", "r"); + + if(fp == NULL) exit(EXIT_FAILURE); + + // ------------------------- // + + // Fill games list + while((read = getline(&line, &len, fp)) != -1) { + + Game game; + + game_start(&game); + game_read(&game, line); + list_insert(game); + } + + // ------------------------- // + + fclose(fp); + + if(line) free(line); + + // ------------------------------------------------------------ // + + // Second part - Print .in games + + char in[15]; + scanf(" %[^\n]s", in); + + while(true) { + + if(isFim(in)) break; + else { + + int app_id = atoi(in); + + for(int i = 0; i < n; i++) { + + if(games[i].app_id == app_id) { + + game_print(&games[i]); + break; + } + } + + // ------------------------- // + + scanf(" %[^\n]s", in); + } + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/pedro.out b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pedro.out new file mode 100644 index 0000000..929980c --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pedro.out @@ -0,0 +1,50 @@ +840010 Garden Paws Dec/2018 50000 - 100000 0 19.99 2 [English] http://www.gardenpawsgame.com true true false 92% 5h 46m Bitten Toast Games Inc. [Adventure, Indie, RPG, Simulation] +866510 !AnyWay! Jun/2018 50000 - 100000 0 1.79 37 [English, Russian, French, Italian, German, Polish, Ukrainian, Swedish, Simplified Chinese] null true false false 69% 5h 53m EYEFRONT [Adventure, Casual, Indie] +1970560 Bobbi Adventure May/2022 50000 - 100000 0 24.99 0 [English] null true false false 67% null Felio Stung ROG [Indie] +411740 Yet Another World Nov/2015 50000 - 100000 0 5.99 0 [English] null true true true 78% 6h 24m Energy Milk [Action, Adventure, Indie] +1509590 Fujiwara Bittersweet Jan/2021 50000 - 100000 0 0.00 0 [English] null true true true 91% null MagicBenchVN [Free to Play, Indie] +458520 Wrath of Anna Apr/2018 50000 - 100000 0 19.99 1 [English, Spanish - Spain, Hungarian, German, Norwegian, Polish, Swedish, Russian] http://LorenzoEnt.com true false false 35% 2h 50m Lorenzo Ent.,Michael L. Fiorentino Gutierrez [Action, Adventure, Indie] +920210 LEGO® Star Wars™: The Skywalker Saga Apr/2022 500000 - 1000000 0 49.99 8 [English, French, Italian, German, Spanish - Spain, Arabic, Danish, Dutch, Korean, Polish, Portuguese - Brazil, Russian, Spanish - Latin America, Traditional Chinese, Japanese] null true false false 92% 22h 42m TT Games [Action, Adventure] +1444020 Reactor Tech² Aug/2021 50000 - 100000 0 14.99 0 [English, Russian] null true false false 68% null 4Co [Indie, Simulation, Strategy] +1232460 Onee Chanbara ORIGIN Oct/2020 50000 - 100000 18 59.99 96 [English, Simplified Chinese, Traditional Chinese, Japanese, Korean] null true false false 72% 2h 25m Tamsoft [Action] +2026070 Tank Commander: Battlefield Jul/2022 50000 - 100000 0 2.99 0 [English] null true false false 100% null SP GAMES [Action, Indie, Simulation] +258880 Professional Farmer 2014 Nov/2013 50000 - 100000 0 2.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Russian, Dutch, Swedish, Norwegian] http://www.professional-farmer.com/ true false false 46% 32h 9m PlayWay S.A. [Simulation] +295250 Stranded May/2014 50000 - 100000 0 0.49 0 [English] null true true true 35% 3h 56m Peter Moorhead [Adventure, Indie] +299500 International Snooker May/2014 50000 - 100000 0 5.99 0 [English] http://www.bigheadgames.co.uk/ true false false 62% 1h 11m Big Head Games Ltd [Casual, Sports] +574080 Fog of War Jun/2018 50000 - 100000 0 4.99 1 [English, Russian] null true false false 48% 6h 14m Monkeys Lab. [Action, Indie, Massively Multiplayer, RPG, Simulation, Strategy] +598780 Boreal Blade Nov/2020 50000 - 100000 0 3.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese] https://www.borealblade.com true false false 66% null Frozenbyte [Action, Early Access] +1217190 浮世万千之前世今生 Jan/2020 50000 - 100000 0 5.49 1 [Simplified Chinese] null true false false 78% null 飞天大胖喵 [Adventure, Casual, Indie, RPG, Strategy] +257730 Infinity Wars: Animated Trading Card Game Sep/2014 500000 - 1000000 0 0.00 0 [English, Simplified Chinese] http://www.infinitywarsgame.com true false false 77% 6h 24m Lightmare Studios [Indie, Massively Multiplayer, Strategy] +1807730 Lab Bio-Terror Dec/2021 50000 - 100000 0 12.99 0 [English] null true false false 82% null VOLTECH [Action, Indie] +773670 Delete Jan/2018 50000 - 100000 0 1.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean] null true true false 96% 1h 24m PONY [Casual, Indie] +1803150 Void Slayer Jan/2022 50000 - 100000 0 4.99 0 [English] null true false false 79% null Madmind Studio: After hours [Action, Indie] +1573070 Endless Furry Blackjack Mar/2021 50000 - 100000 0 0.99 0 [English] https://m.youtube.com/ericyoungvfx/ true false false 20% null Tegridy Made Games [Casual, Indie, Sports, Strategy] +513930 J.U.R : Japan Underground Racing Aug/2016 50000 - 100000 0 0.49 0 [English] null true false false 32% null JDM4iK [Casual, Indie, Racing, Simulation] +385250 Paint it Back Oct/2015 50000 - 100000 0 7.99 0 [English] http://casuallabs.com/wp/?page_id=24 true true true 98% null Casual Labs [Casual] +261880 Corporate Lifestyle Simulator Mar/2014 50000 - 100000 0 4.99 1 [English] http://www.dolphinbarn.com true false false 83% 4h 7m DolphinBarn [Action, Casual, Indie] +533300 Zup! Oct/2016 500000 - 1000000 0 0.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Portuguese - Brazil, Hungarian, Greek, Danish, Traditional Chinese, Simplified Chinese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Thai, Turkish, Ukrainian, Finnish, Czech, Swedish, Japanese] http://quietriver.info/ true false false 94% 1h 42m Quiet River [Casual, Indie] +542340 Slingshot people Oct/2016 500000 - 1000000 0 0.99 0 [English] http://www.vsemagy.ru/index.php true false false 47% 3h 50m StalkerAlex [Action, Casual, Indie, Simulation] +1209040 Cyber Hunter Jun/2020 500000 - 1000000 0 0.00 0 [English, French, German, Spanish - Spain, Russian, Japanese, Simplified Chinese, Traditional Chinese, Portuguese - Brazil, Korean, Thai, Vietnamese] https://www.cyberhunter.game/ true false false 73% 5h 41m NetEase Games [Action, Free to Play, Massively Multiplayer] +8790 GTR 2 FIA GT Racing Game Dec/2012 50000 - 100000 0 7.99 0 [English] http://www.simbin.com/games/gtr2/ true false false 93% 11m SimBin Studios AB [Racing, Simulation, Sports] +8000 Tomb Raider: Anniversary Jun/2007 500000 - 1000000 13 8.99 0 [English, French, German, Italian, Spanish - Spain] http://www.tombraider.com/anniversary/ true false false 82% 6h Crystal Dynamics [Action, Adventure] +415150 Pang Adventures Apr/2016 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Portuguese - Brazil, Russian] https://www.facebook.com/Pang.Adventures/ true false false 80% 3h 29m Dotemu [Action, Casual, Strategy] +2012500 The Katydids Incident Jun/2022 50000 - 100000 0 4.99 0 [English] https://punxstudios.co true false false 100% null Punx Studios [Indie, Simulation] +691150 Saku Saku: Love Blooms with the Cherry Blossoms Oct/2017 50000 - 100000 0 19.99 0 [English] null true false false 92% 5h 16m PALETTE [Sexual Content, Nudity, Casual] +283370 Marine Sharpshooter II: Jungle Warfare Apr/2014 50000 - 100000 0 2.99 0 [English] http://www.funboxmedia.co.uk/ true false false 32% 2h 3m Jarhead Games [Action] +249650 Blackguards Jan/2014 500000 - 1000000 0 0.99 2 [English, German, French, Spanish - Spain, Portuguese - Brazil, Russian, Italian, Japanese, Korean, Czech, Turkish, Polish, Simplified Chinese] http://www.blackguards-game.com true false false 62% 8h 58m Daedalic Entertainment [Indie, RPG, Strategy] +268870 Satellite Reign Aug/2015 500000 - 1000000 0 29.99 3 [English, French, Italian, German, Spanish - Spain, Czech, Russian] http://www.satellitereign.com/ true true true 71% 5h 18m 5 Lives Studios [Action, Indie, Strategy] +1172510 Unlock The King Nov/2019 50000 - 100000 0 0.99 0 [English] null true true false 96% null Minimol Games [Casual, Strategy] +927890 Hentai Girl Linda Dec/2018 50000 - 100000 0 0.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean, Spanish - Latin America, Vietnamese] null true true false 94% 1h 13m GirlGames [Casual, Indie, RPG, Simulation] +25700 Madballs in Babo:Invasion Sep/2009 50000 - 100000 0 4.99 7 [English, German, Korean, Portuguese, Spanish - Spain, French, Italian, Russian] http://www.baboinvasion.com true true false 84% 4h 15m Playbrains [Action, Casual, Indie] +281610 Homeworld: Deserts of Kharak Jan/2016 500000 - 1000000 0 49.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Polish] http://www.desertsofkharak.com true true false 83% 8h 32m Blackbird Interactive [Strategy] +485610 Ball 3D: Soccer Online Mar/2017 500000 - 1000000 0 9.99 0 [English] http://www.ball3d.com true true false 83% 2h 49m Unusualsoft [Sports] +1276850 Kane's Shadow Apr/2020 50000 - 100000 0 0.00 0 [English] null true true false 67% null Plush Productions LLC [Casual, Indie] +722340 Captain vs Sky Pirates Oct/2017 50000 - 100000 0 2.99 5 [English] https://store.steampowered.com/publisher/boogygames/ true false false 25% null Boogygames Studios [Action, Adventure, Indie, Strategy] +1499640 Y.E.T.I Jan/2021 50000 - 100000 0 0.49 0 [English] https://anpa.us true false false 80% null Racing Bros [Action, Indie] +1848450 Nightmare of Decay May/2022 50000 - 100000 0 3.99 0 [English, French, Polish, Russian, Simplified Chinese, Traditional Chinese, Spanish - Latin America, Portuguese - Brazil, Italian, German, Czech, Hungarian, Turkish, Norwegian, Swedish] null true false false 98% 5h 56m Checkmaty [Action, Adventure, Indie] +615700 A Plunge into Darkness Mar/2020 50000 - 100000 0 5.99 1 [English] https://www.aldorlea.org/ true false false 73% null Aldorlea [Adventure, Indie, RPG, Simulation, Strategy] +744980 Super Club Soccer Oct/2019 50000 - 100000 0 0.00 0 [English] http://www.superclubsoccer.com/ true false true 69% null Trick27 Studios Limited [Free to Play, Massively Multiplayer, Sports, Early Access] +10180 Call of Duty®: Modern Warfare® 2 (2009) Nov/2009 5000000 - 10000000 0 19.99 2 [English, French, German, Italian, Spanish - Spain] https://www.callofduty.com/ true true false 93% 12h 56m Infinity Ward [Action] +234390 Teleglitch: Die More Edition Jul/2013 500000 - 1000000 0 3.24 1 [English] http://www.teleglitch.com true true true 85% 2h 20m Test3 Projects [Action, Indie] +1641670 EdgeOfTheAbyssAwaken Jun/2022 50000 - 100000 0 18.99 3 [English, Simplified Chinese] null true false false 74% null TrinityBJ [Action, Indie, RPG, Strategy] +427520 Factorio Aug/2020 5000000 - 10000000 0 30.00 1 [English, French, Italian, German, Spanish - Spain, Hungarian, Dutch, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Finnish, Swedish, Czech, Russian, Ukrainian, Japanese, Simplified Chinese, Traditional Chinese, Korean, Turkish] https://www.factorio.com true true true 97% 89h 43m Wube Software LTD. [Casual, Indie, Simulation, Strategy] diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.in b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.in new file mode 100644 index 0000000..cf004e0 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.in @@ -0,0 +1,51 @@ +840010 +866510 +1970560 +411740 +1509590 +458520 +920210 +1444020 +1232460 +2026070 +258880 +295250 +299500 +574080 +598780 +1217190 +257730 +1807730 +773670 +1803150 +1573070 +513930 +385250 +261880 +533300 +542340 +1209040 +8790 +8000 +415150 +2012500 +691150 +283370 +249650 +268870 +1172510 +927890 +25700 +281610 +485610 +1276850 +722340 +1499640 +1848450 +615700 +744980 +10180 +234390 +1641670 +427520 +FIM diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.out b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.out new file mode 100644 index 0000000..929980c --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/pub.out @@ -0,0 +1,50 @@ +840010 Garden Paws Dec/2018 50000 - 100000 0 19.99 2 [English] http://www.gardenpawsgame.com true true false 92% 5h 46m Bitten Toast Games Inc. [Adventure, Indie, RPG, Simulation] +866510 !AnyWay! Jun/2018 50000 - 100000 0 1.79 37 [English, Russian, French, Italian, German, Polish, Ukrainian, Swedish, Simplified Chinese] null true false false 69% 5h 53m EYEFRONT [Adventure, Casual, Indie] +1970560 Bobbi Adventure May/2022 50000 - 100000 0 24.99 0 [English] null true false false 67% null Felio Stung ROG [Indie] +411740 Yet Another World Nov/2015 50000 - 100000 0 5.99 0 [English] null true true true 78% 6h 24m Energy Milk [Action, Adventure, Indie] +1509590 Fujiwara Bittersweet Jan/2021 50000 - 100000 0 0.00 0 [English] null true true true 91% null MagicBenchVN [Free to Play, Indie] +458520 Wrath of Anna Apr/2018 50000 - 100000 0 19.99 1 [English, Spanish - Spain, Hungarian, German, Norwegian, Polish, Swedish, Russian] http://LorenzoEnt.com true false false 35% 2h 50m Lorenzo Ent.,Michael L. Fiorentino Gutierrez [Action, Adventure, Indie] +920210 LEGO® Star Wars™: The Skywalker Saga Apr/2022 500000 - 1000000 0 49.99 8 [English, French, Italian, German, Spanish - Spain, Arabic, Danish, Dutch, Korean, Polish, Portuguese - Brazil, Russian, Spanish - Latin America, Traditional Chinese, Japanese] null true false false 92% 22h 42m TT Games [Action, Adventure] +1444020 Reactor Tech² Aug/2021 50000 - 100000 0 14.99 0 [English, Russian] null true false false 68% null 4Co [Indie, Simulation, Strategy] +1232460 Onee Chanbara ORIGIN Oct/2020 50000 - 100000 18 59.99 96 [English, Simplified Chinese, Traditional Chinese, Japanese, Korean] null true false false 72% 2h 25m Tamsoft [Action] +2026070 Tank Commander: Battlefield Jul/2022 50000 - 100000 0 2.99 0 [English] null true false false 100% null SP GAMES [Action, Indie, Simulation] +258880 Professional Farmer 2014 Nov/2013 50000 - 100000 0 2.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Russian, Dutch, Swedish, Norwegian] http://www.professional-farmer.com/ true false false 46% 32h 9m PlayWay S.A. [Simulation] +295250 Stranded May/2014 50000 - 100000 0 0.49 0 [English] null true true true 35% 3h 56m Peter Moorhead [Adventure, Indie] +299500 International Snooker May/2014 50000 - 100000 0 5.99 0 [English] http://www.bigheadgames.co.uk/ true false false 62% 1h 11m Big Head Games Ltd [Casual, Sports] +574080 Fog of War Jun/2018 50000 - 100000 0 4.99 1 [English, Russian] null true false false 48% 6h 14m Monkeys Lab. [Action, Indie, Massively Multiplayer, RPG, Simulation, Strategy] +598780 Boreal Blade Nov/2020 50000 - 100000 0 3.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese] https://www.borealblade.com true false false 66% null Frozenbyte [Action, Early Access] +1217190 浮世万千之前世今生 Jan/2020 50000 - 100000 0 5.49 1 [Simplified Chinese] null true false false 78% null 飞天大胖喵 [Adventure, Casual, Indie, RPG, Strategy] +257730 Infinity Wars: Animated Trading Card Game Sep/2014 500000 - 1000000 0 0.00 0 [English, Simplified Chinese] http://www.infinitywarsgame.com true false false 77% 6h 24m Lightmare Studios [Indie, Massively Multiplayer, Strategy] +1807730 Lab Bio-Terror Dec/2021 50000 - 100000 0 12.99 0 [English] null true false false 82% null VOLTECH [Action, Indie] +773670 Delete Jan/2018 50000 - 100000 0 1.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean] null true true false 96% 1h 24m PONY [Casual, Indie] +1803150 Void Slayer Jan/2022 50000 - 100000 0 4.99 0 [English] null true false false 79% null Madmind Studio: After hours [Action, Indie] +1573070 Endless Furry Blackjack Mar/2021 50000 - 100000 0 0.99 0 [English] https://m.youtube.com/ericyoungvfx/ true false false 20% null Tegridy Made Games [Casual, Indie, Sports, Strategy] +513930 J.U.R : Japan Underground Racing Aug/2016 50000 - 100000 0 0.49 0 [English] null true false false 32% null JDM4iK [Casual, Indie, Racing, Simulation] +385250 Paint it Back Oct/2015 50000 - 100000 0 7.99 0 [English] http://casuallabs.com/wp/?page_id=24 true true true 98% null Casual Labs [Casual] +261880 Corporate Lifestyle Simulator Mar/2014 50000 - 100000 0 4.99 1 [English] http://www.dolphinbarn.com true false false 83% 4h 7m DolphinBarn [Action, Casual, Indie] +533300 Zup! Oct/2016 500000 - 1000000 0 0.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Portuguese - Brazil, Hungarian, Greek, Danish, Traditional Chinese, Simplified Chinese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Thai, Turkish, Ukrainian, Finnish, Czech, Swedish, Japanese] http://quietriver.info/ true false false 94% 1h 42m Quiet River [Casual, Indie] +542340 Slingshot people Oct/2016 500000 - 1000000 0 0.99 0 [English] http://www.vsemagy.ru/index.php true false false 47% 3h 50m StalkerAlex [Action, Casual, Indie, Simulation] +1209040 Cyber Hunter Jun/2020 500000 - 1000000 0 0.00 0 [English, French, German, Spanish - Spain, Russian, Japanese, Simplified Chinese, Traditional Chinese, Portuguese - Brazil, Korean, Thai, Vietnamese] https://www.cyberhunter.game/ true false false 73% 5h 41m NetEase Games [Action, Free to Play, Massively Multiplayer] +8790 GTR 2 FIA GT Racing Game Dec/2012 50000 - 100000 0 7.99 0 [English] http://www.simbin.com/games/gtr2/ true false false 93% 11m SimBin Studios AB [Racing, Simulation, Sports] +8000 Tomb Raider: Anniversary Jun/2007 500000 - 1000000 13 8.99 0 [English, French, German, Italian, Spanish - Spain] http://www.tombraider.com/anniversary/ true false false 82% 6h Crystal Dynamics [Action, Adventure] +415150 Pang Adventures Apr/2016 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Portuguese - Brazil, Russian] https://www.facebook.com/Pang.Adventures/ true false false 80% 3h 29m Dotemu [Action, Casual, Strategy] +2012500 The Katydids Incident Jun/2022 50000 - 100000 0 4.99 0 [English] https://punxstudios.co true false false 100% null Punx Studios [Indie, Simulation] +691150 Saku Saku: Love Blooms with the Cherry Blossoms Oct/2017 50000 - 100000 0 19.99 0 [English] null true false false 92% 5h 16m PALETTE [Sexual Content, Nudity, Casual] +283370 Marine Sharpshooter II: Jungle Warfare Apr/2014 50000 - 100000 0 2.99 0 [English] http://www.funboxmedia.co.uk/ true false false 32% 2h 3m Jarhead Games [Action] +249650 Blackguards Jan/2014 500000 - 1000000 0 0.99 2 [English, German, French, Spanish - Spain, Portuguese - Brazil, Russian, Italian, Japanese, Korean, Czech, Turkish, Polish, Simplified Chinese] http://www.blackguards-game.com true false false 62% 8h 58m Daedalic Entertainment [Indie, RPG, Strategy] +268870 Satellite Reign Aug/2015 500000 - 1000000 0 29.99 3 [English, French, Italian, German, Spanish - Spain, Czech, Russian] http://www.satellitereign.com/ true true true 71% 5h 18m 5 Lives Studios [Action, Indie, Strategy] +1172510 Unlock The King Nov/2019 50000 - 100000 0 0.99 0 [English] null true true false 96% null Minimol Games [Casual, Strategy] +927890 Hentai Girl Linda Dec/2018 50000 - 100000 0 0.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Ukrainian, Russian, Bulgarian, Hungarian, Turkish, Greek, Norwegian, Czech, Japanese, Polish, Thai, Swedish, Simplified Chinese, Traditional Chinese, Romanian, Finnish, Dutch, Portuguese, Portuguese - Brazil, Arabic, Korean, Spanish - Latin America, Vietnamese] null true true false 94% 1h 13m GirlGames [Casual, Indie, RPG, Simulation] +25700 Madballs in Babo:Invasion Sep/2009 50000 - 100000 0 4.99 7 [English, German, Korean, Portuguese, Spanish - Spain, French, Italian, Russian] http://www.baboinvasion.com true true false 84% 4h 15m Playbrains [Action, Casual, Indie] +281610 Homeworld: Deserts of Kharak Jan/2016 500000 - 1000000 0 49.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Polish] http://www.desertsofkharak.com true true false 83% 8h 32m Blackbird Interactive [Strategy] +485610 Ball 3D: Soccer Online Mar/2017 500000 - 1000000 0 9.99 0 [English] http://www.ball3d.com true true false 83% 2h 49m Unusualsoft [Sports] +1276850 Kane's Shadow Apr/2020 50000 - 100000 0 0.00 0 [English] null true true false 67% null Plush Productions LLC [Casual, Indie] +722340 Captain vs Sky Pirates Oct/2017 50000 - 100000 0 2.99 5 [English] https://store.steampowered.com/publisher/boogygames/ true false false 25% null Boogygames Studios [Action, Adventure, Indie, Strategy] +1499640 Y.E.T.I Jan/2021 50000 - 100000 0 0.49 0 [English] https://anpa.us true false false 80% null Racing Bros [Action, Indie] +1848450 Nightmare of Decay May/2022 50000 - 100000 0 3.99 0 [English, French, Polish, Russian, Simplified Chinese, Traditional Chinese, Spanish - Latin America, Portuguese - Brazil, Italian, German, Czech, Hungarian, Turkish, Norwegian, Swedish] null true false false 98% 5h 56m Checkmaty [Action, Adventure, Indie] +615700 A Plunge into Darkness Mar/2020 50000 - 100000 0 5.99 1 [English] https://www.aldorlea.org/ true false false 73% null Aldorlea [Adventure, Indie, RPG, Simulation, Strategy] +744980 Super Club Soccer Oct/2019 50000 - 100000 0 0.00 0 [English] http://www.superclubsoccer.com/ true false true 69% null Trick27 Studios Limited [Free to Play, Massively Multiplayer, Sports, Early Access] +10180 Call of Duty®: Modern Warfare® 2 (2009) Nov/2009 5000000 - 10000000 0 19.99 2 [English, French, German, Italian, Spanish - Spain] https://www.callofduty.com/ true true false 93% 12h 56m Infinity Ward [Action] +234390 Teleglitch: Die More Edition Jul/2013 500000 - 1000000 0 3.24 1 [English] http://www.teleglitch.com true true true 85% 2h 20m Test3 Projects [Action, Indie] +1641670 EdgeOfTheAbyssAwaken Jun/2022 50000 - 100000 0 18.99 3 [English, Simplified Chinese] null true false false 74% null TrinityBJ [Action, Indie, RPG, Strategy] +427520 Factorio Aug/2020 5000000 - 10000000 0 30.00 1 [English, French, Italian, German, Spanish - Spain, Hungarian, Dutch, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Finnish, Swedish, Czech, Russian, Ukrainian, Japanese, Simplified Chinese, Traditional Chinese, Korean, Turkish] https://www.factorio.com true true true 97% 89h 43m Wube Software LTD. [Casual, Indie, Simulation, Strategy] From a1cfa86c6382b003d028d5151ff03b8998ee5faf Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:08:31 -0300 Subject: [PATCH 03/13] Adiciona gabarito - TP02Q03 --- .../753045_sequencial.txt | 1 + .../Arq.java | 204 ++++++ .../Game.java | 595 ++++++++++++++++++ .../pedro.out | 39 ++ .../pub.in | 91 +++ .../pub.out | 39 ++ 6 files changed, 969 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Arq.java create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pedro.out create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.out diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt new file mode 100644 index 0000000..4846eef --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt @@ -0,0 +1 @@ +753045 24ms 1933 \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Arq.java b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Arq.java new file mode 100644 index 0000000..01f3146 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Arq.java @@ -0,0 +1,204 @@ +import java.util.Formatter; +import java.util.Scanner; +import java.io.File; + +public class Arq +{ + private static String nomeArquivo = ""; + private static String charsetArquivo = "ISO-8859-1"; + private static boolean write = false, read = false; + private static Formatter saida = null; + private static Scanner entrada = null; + + public static boolean openWrite(String nomeArq, String charset) { + boolean resp = false; + close(); + try{ + saida = new Formatter(nomeArq, charset); + nomeArquivo = nomeArq; + resp = write = true; + } catch (Exception e) {} + return resp; + } + + public static boolean openWrite(String nomeArq) { + return openWrite(nomeArq, charsetArquivo); + } + + public static boolean openWriteClose(String nomeArq, String charset, String conteudo) { + boolean resp = openWrite(nomeArq, charset); + if(resp == true){ + println(conteudo); + close(); + } + return resp; + } + + public static boolean openWriteClose(String nomeArq, String conteudo) { + return openWriteClose(nomeArq, charsetArquivo, conteudo); + } + + public static boolean openRead(String nomeArq) { + return openRead(nomeArq, charsetArquivo); + } + + public static boolean openRead(String nomeArq, String charset) { + boolean resp = false; + close(); + try{ + entrada = new Scanner(new File(nomeArq), charset); + nomeArquivo = nomeArq; + resp = read = true; + } catch (Exception e) {} + return resp; + } + + public static String openReadClose(String nomeArq){ + openRead(nomeArq); + String resp = readAll(); + close(); + return resp; + } + + public static void close() { + if(write == true){ + saida.close(); + } + if(read == true){ + entrada.close(); + } + write = read = false; + nomeArquivo = ""; + charsetArquivo = "ISO-8859-1"; + } + + public static long length(){ + long resp = -1; + if(read != write){ + File file = new File(nomeArquivo); + resp = file.length(); + } + return resp; + } + + public static void print(int x){ + if(write == true){ + saida.format( "%d", x); + } + } + + public static void print(double x){ + if(write == true){ + saida.format( "%f", x); + } + } + + public static void print(String x){ + if(write == true){ + saida.format( "%s", x); + } + } + + public static void print(boolean x){ + if(write == true){ + saida.format( "%s", ((x) ? "true" : "false")); + } + } + + public static void print(char x){ + if(write == true){ + saida.format( "%c", x); + } + } + + public static void println(int x){ + if(write == true){ + saida.format( "%d\n", x); + } + } + + public static void println(double x){ + if(write == true){ + saida.format( "%f\n", x); + } + } + + public static void println(String x){ + if(write == true){ + saida.format( "%s\n", x); + } + } + + public static void println(boolean x){ + if(write == true){ + saida.format( "%s\n", ((x) ? "true" : "false")); + } + } + + public static void println(char x){ + if(write == true){ + saida.format( "%c\n", x); + } + } + + public static int readInt(){ + int resp = -1; + try{ + resp = entrada.nextInt(); + } catch (Exception e) {} + return resp; + } + + public static char readChar(){ + char resp = ' '; + try{ + resp = (char)entrada.nextByte(); + } catch (Exception e) {} + return resp; + } + + public static double readDouble(){ + double resp = -1; + try{ + resp = Double.parseDouble(readString().replace(",",".")); + } catch (Exception e) {} + return resp; + } + + public static String readString(){ + String resp = ""; + try{ + resp = entrada.next(); + } catch (Exception e) { System.out.println(e.getMessage()); } + return resp; + } + + public static boolean readBoolean(){ + boolean resp = false; + try{ + resp = (entrada.next().equals("true")) ? true : false; + } catch (Exception e) {} + return resp; + } + + public static String readLine(){ + String resp = ""; + try{ + resp = entrada.nextLine(); + } catch (Exception e) { System.out.println(e.getMessage()); } + return resp; + } + + + public static boolean hasNext(){ + return entrada.hasNext(); + } + + public static String readAll(){ + String resp = ""; + while(hasNext()){ + resp += (readLine() + "\n"); + } + return resp; + } +} diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java new file mode 100644 index 0000000..cd344b0 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java @@ -0,0 +1,595 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + Scanner scr = new Scanner(System.in); + ArrayList gamesToAdd = new ArrayList(); + ArrayList games = new ArrayList(); + String line = scr.nextLine(); + + // ------------------------------------------------------------------------------ // + + // Fill list with requested ids + while(true) { + + if(line.equals("FIM")) break; + + gamesToAdd.add(Integer.parseInt(line)); + + line = scr.nextLine(); + } + + // ------------------------------------------------------------------------------ // + + // Add requested ids to games list + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream("/tmp/games.csv"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + while((line = br.readLine()) != null) { + + if(gamesToAdd.contains(Integer.parseInt(line.substring(0, line.indexOf(','))))) { + + Game game = new Game(); + + game.read(line); + games.add(game); + } + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Initialize bench log + int c_compares = 0; + long t_begin = System.currentTimeMillis(); + + // Search in games list by name + line = scr.nextLine(); + + while(true) { + + if(line.equals("FIM")) break; + + // ------------------------------------ // + + boolean found = false; + + for(int i = 0; i < games.size(); i++) { + + c_compares++; + + if(games.get(i).name.compareTo(line) == 0) { + + found = true; + break; + } + } + + // ------------------------------------ // + + System.out.println(found ? "SIM" : "NAO"); + + line = scr.nextLine(); + } + + Arq.openWrite("753045_sequencial.txt"); + Arq.print("753045\t" + (System.currentTimeMillis() - t_begin) + "ms\t" + c_compares); + Arq.close(); + + scr.close(); + + // ---------------------------------------------------------------------------------------------- // + + } + + // ---------------------------------------------------------------------------------------------- // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pedro.out b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pedro.out new file mode 100644 index 0000000..ed66dd8 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pedro.out @@ -0,0 +1,39 @@ +SIM +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.in b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.in new file mode 100644 index 0000000..6e08b8d --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.in @@ -0,0 +1,91 @@ +840010 +866510 +1970560 +411740 +1509590 +458520 +920210 +1444020 +1232460 +2026070 +258880 +295250 +299500 +574080 +598780 +1217190 +257730 +1807730 +773670 +1803150 +1573070 +513930 +385250 +261880 +533300 +542340 +1209040 +8790 +8000 +415150 +2012500 +691150 +283370 +249650 +268870 +1172510 +927890 +25700 +281610 +485610 +1276850 +722340 +1499640 +1848450 +615700 +744980 +10180 +234390 +1641670 +427520 +FIM +Bobbi Adventure +The Test: Hypothesis Rising +Epic Cards Battle 2 (TCG) +Omensight: Definitive Edition +Gray Matter +The Legend of Bean +Armored Warfare +Void Slayer +RacetronicVR +The Amazing American Circus +Your Quest +HistoryMaker VR +WE ARE FOOTBALL +Rise of Insanity +Aragami +BONEWORKS +CAGE +Saku Saku: Love Blooms with the Cherry Blossoms +Kill The Bad Guy +Deisim +Redactem +Xuan-Yuan Sword: The Gate of Firmament +Subspace Continuum +DRAGON BALL XENOVERSE +RiotZ +Stephen's Sausage Roll +Tavern Tycoon - Dragon's Hangover +Child of Light +Heart and Seoul +Tank Destroyer +Claire +MONOLISK +Cinderella Escape 2 Revenge +Flat Heroes +The Political Machine 2016 +AFFECTED: The Manor - The Complete Edition +QUAKE III: Team Arena +Woodcutter Simulator 2013 +Dawn of Man +FIM \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.out b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.out new file mode 100644 index 0000000..ed66dd8 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/pub.out @@ -0,0 +1,39 @@ +SIM +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO From ee7d40319a0d551524ae303b6a737d4f38d5240b Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:08:57 -0300 Subject: [PATCH 04/13] Adiciona gabarito - TP02Q04 --- .../753045_sequencial.txt | 1 + .../Arq.java | 204 ++++++ .../Game.java | 615 ++++++++++++++++++ .../pedro.out | 39 ++ .../TP02Q04 - Pesquisa binária em Java/pub.in | 91 +++ .../pub.out | 39 ++ 6 files changed, 989 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Arq.java create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pedro.out create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.out diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt new file mode 100644 index 0000000..f3866b4 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt @@ -0,0 +1 @@ +753045 21ms 453 \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Arq.java b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Arq.java new file mode 100644 index 0000000..01f3146 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Arq.java @@ -0,0 +1,204 @@ +import java.util.Formatter; +import java.util.Scanner; +import java.io.File; + +public class Arq +{ + private static String nomeArquivo = ""; + private static String charsetArquivo = "ISO-8859-1"; + private static boolean write = false, read = false; + private static Formatter saida = null; + private static Scanner entrada = null; + + public static boolean openWrite(String nomeArq, String charset) { + boolean resp = false; + close(); + try{ + saida = new Formatter(nomeArq, charset); + nomeArquivo = nomeArq; + resp = write = true; + } catch (Exception e) {} + return resp; + } + + public static boolean openWrite(String nomeArq) { + return openWrite(nomeArq, charsetArquivo); + } + + public static boolean openWriteClose(String nomeArq, String charset, String conteudo) { + boolean resp = openWrite(nomeArq, charset); + if(resp == true){ + println(conteudo); + close(); + } + return resp; + } + + public static boolean openWriteClose(String nomeArq, String conteudo) { + return openWriteClose(nomeArq, charsetArquivo, conteudo); + } + + public static boolean openRead(String nomeArq) { + return openRead(nomeArq, charsetArquivo); + } + + public static boolean openRead(String nomeArq, String charset) { + boolean resp = false; + close(); + try{ + entrada = new Scanner(new File(nomeArq), charset); + nomeArquivo = nomeArq; + resp = read = true; + } catch (Exception e) {} + return resp; + } + + public static String openReadClose(String nomeArq){ + openRead(nomeArq); + String resp = readAll(); + close(); + return resp; + } + + public static void close() { + if(write == true){ + saida.close(); + } + if(read == true){ + entrada.close(); + } + write = read = false; + nomeArquivo = ""; + charsetArquivo = "ISO-8859-1"; + } + + public static long length(){ + long resp = -1; + if(read != write){ + File file = new File(nomeArquivo); + resp = file.length(); + } + return resp; + } + + public static void print(int x){ + if(write == true){ + saida.format( "%d", x); + } + } + + public static void print(double x){ + if(write == true){ + saida.format( "%f", x); + } + } + + public static void print(String x){ + if(write == true){ + saida.format( "%s", x); + } + } + + public static void print(boolean x){ + if(write == true){ + saida.format( "%s", ((x) ? "true" : "false")); + } + } + + public static void print(char x){ + if(write == true){ + saida.format( "%c", x); + } + } + + public static void println(int x){ + if(write == true){ + saida.format( "%d\n", x); + } + } + + public static void println(double x){ + if(write == true){ + saida.format( "%f\n", x); + } + } + + public static void println(String x){ + if(write == true){ + saida.format( "%s\n", x); + } + } + + public static void println(boolean x){ + if(write == true){ + saida.format( "%s\n", ((x) ? "true" : "false")); + } + } + + public static void println(char x){ + if(write == true){ + saida.format( "%c\n", x); + } + } + + public static int readInt(){ + int resp = -1; + try{ + resp = entrada.nextInt(); + } catch (Exception e) {} + return resp; + } + + public static char readChar(){ + char resp = ' '; + try{ + resp = (char)entrada.nextByte(); + } catch (Exception e) {} + return resp; + } + + public static double readDouble(){ + double resp = -1; + try{ + resp = Double.parseDouble(readString().replace(",",".")); + } catch (Exception e) {} + return resp; + } + + public static String readString(){ + String resp = ""; + try{ + resp = entrada.next(); + } catch (Exception e) { System.out.println(e.getMessage()); } + return resp; + } + + public static boolean readBoolean(){ + boolean resp = false; + try{ + resp = (entrada.next().equals("true")) ? true : false; + } catch (Exception e) {} + return resp; + } + + public static String readLine(){ + String resp = ""; + try{ + resp = entrada.nextLine(); + } catch (Exception e) { System.out.println(e.getMessage()); } + return resp; + } + + + public static boolean hasNext(){ + return entrada.hasNext(); + } + + public static String readAll(){ + String resp = ""; + while(hasNext()){ + resp += (readLine() + "\n"); + } + return resp; + } +} diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java new file mode 100644 index 0000000..83fd29f --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java @@ -0,0 +1,615 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game implements Comparable { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public int compareTo(Game other) { return this.name.compareTo(other.name); } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + Scanner scr = new Scanner(System.in); + ArrayList gamesToAdd = new ArrayList(); + ArrayList games = new ArrayList(); + String line = scr.nextLine(); + + // ------------------------------------------------------------------------------ // + + // Fill list with requested ids + while(true) { + + if(line.equals("FIM")) break; + + gamesToAdd.add(Integer.parseInt(line)); + + line = scr.nextLine(); + } + + // ------------------------------------------------------------------------------ // + + // Add requested ids to games list + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream("/tmp/games.csv"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + while((line = br.readLine()) != null) { + + if(gamesToAdd.contains(Integer.parseInt(line.substring(0, line.indexOf(','))))) { + + Game game = new Game(); + + game.read(line); + games.add(game); + } + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Initialize bench log + int c_compares = 0; + long t_begin = System.currentTimeMillis(); + + Collections.sort(games); + + // Search in games list by name + line = scr.nextLine(); + + while(true) { + + if(line.equals("FIM")) break; + + // ------------------------------------ // + + boolean found = false; + + int low = 0; + int high = games.size() - 1; + + while(low <= high) { + + int mid = low + (high - low) / 2; + + c_compares++; + + if(games.get(mid).name.compareTo(line) == 0) { + + found = true; + break; + } + else if(games.get(mid).name.compareTo(line) < 0) { + + c_compares++; + low = mid + 1; + } + else { + + c_compares++; + high = mid - 1; + } + } + + // ------------------------------------ // + + System.out.println(found ? "SIM" : "NAO"); + + line = scr.nextLine(); + } + + Arq.openWrite("753045_sequencial.txt"); + Arq.print("753045\t" + (System.currentTimeMillis() - t_begin) + "ms\t" + c_compares); + Arq.close(); + + scr.close(); + + // ---------------------------------------------------------------------------------------------- // + + } + + // ---------------------------------------------------------------------------------------------- // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pedro.out b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pedro.out new file mode 100644 index 0000000..ed66dd8 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pedro.out @@ -0,0 +1,39 @@ +SIM +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.in b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.in new file mode 100644 index 0000000..6e08b8d --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.in @@ -0,0 +1,91 @@ +840010 +866510 +1970560 +411740 +1509590 +458520 +920210 +1444020 +1232460 +2026070 +258880 +295250 +299500 +574080 +598780 +1217190 +257730 +1807730 +773670 +1803150 +1573070 +513930 +385250 +261880 +533300 +542340 +1209040 +8790 +8000 +415150 +2012500 +691150 +283370 +249650 +268870 +1172510 +927890 +25700 +281610 +485610 +1276850 +722340 +1499640 +1848450 +615700 +744980 +10180 +234390 +1641670 +427520 +FIM +Bobbi Adventure +The Test: Hypothesis Rising +Epic Cards Battle 2 (TCG) +Omensight: Definitive Edition +Gray Matter +The Legend of Bean +Armored Warfare +Void Slayer +RacetronicVR +The Amazing American Circus +Your Quest +HistoryMaker VR +WE ARE FOOTBALL +Rise of Insanity +Aragami +BONEWORKS +CAGE +Saku Saku: Love Blooms with the Cherry Blossoms +Kill The Bad Guy +Deisim +Redactem +Xuan-Yuan Sword: The Gate of Firmament +Subspace Continuum +DRAGON BALL XENOVERSE +RiotZ +Stephen's Sausage Roll +Tavern Tycoon - Dragon's Hangover +Child of Light +Heart and Seoul +Tank Destroyer +Claire +MONOLISK +Cinderella Escape 2 Revenge +Flat Heroes +The Political Machine 2016 +AFFECTED: The Manor - The Complete Edition +QUAKE III: Team Arena +Woodcutter Simulator 2013 +Dawn of Man +FIM \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.out b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.out new file mode 100644 index 0000000..ed66dd8 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/pub.out @@ -0,0 +1,39 @@ +SIM +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +SIM +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO +NAO From c01d4bf452d8b3a9c294dea64e9b84e61250337d Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:09:09 -0300 Subject: [PATCH 05/13] Adiciona gabarito - TP02Q05 --- .../Game.java | 727 ++++++++++++++++++ .../TP02Q05 - Lista sequencial em Java/pub.in | 72 ++ .../pub.out | 61 ++ .../saida.out | 61 ++ 4 files changed, 921 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.out create mode 100644 tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/saida.out diff --git a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java new file mode 100644 index 0000000..6810bd5 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java @@ -0,0 +1,727 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class GameList { + + private Game[] array; + private int n; + + public GameList() {} + + public GameList(int size) { + + array = new Game[size]; + n = 0; + } + + public void print() { + + for(int i = 0; i < n; i++) { + + System.out.print("[" + i + "] "); + + array[i].print(); + } + } + + public void insertBegin(Game game) throws Exception { + + if(n >= array.length) throw new Exception("x Insert error: Full list!"); + + for(int i = n; i > 0; i--) array[i] = array[i - 1]; + + array[0] = game; + n++; + } + + public void insertEnd(Game game) throws Exception { + + if(n >= array.length) throw new Exception("x Insert error: Full list"); + + array[n] = game; + n++; + } + + public void insert(Game game, int pos) throws Exception { + + if(n >= array.length || pos < 0 || pos > n) throw new Exception("x Insert error: Full list / Invalid pos"); + + for(int i = n; i > pos; i--) array[i] = array[i - 1]; + + array[pos] = game; + n++; + } + + public Game removeBegin() throws Exception { + + if(n == 0) throw new Exception("x Remove error: Empty list"); + + Game resp = array[0]; + n--; + + for(int i = 0; i < n; i++) array[i] = array[i + 1]; + return resp; + } + + public Game removeEnd() throws Exception { + + if(n == 0) throw new Exception("x Remove error: Empty list"); + return array[--n]; + } + + public Game remove(int pos) throws Exception { + + if(n == 0 || pos < 0 || pos >= n) throw new Exception("x Remove error: Empty list / Invalid pos"); + + Game resp = array[pos]; + n--; + + for(int i = pos; i < n; i++) array[i] = array[i + 1]; + return resp; + } +} + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public static Game gameSearch(ArrayList games, int app_id) { + + for(Game game : games) if(game.getAppId() == app_id) return game; + return null; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + public static String getGameData(String csvFile, int app_id) throws Exception { + + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream(csvFile); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + String line; + + while((line = br.readLine()) != null) { + + String id_s = Integer.toString(app_id); + + if(line.substring(0, line.indexOf(',')).equals(id_s)) { + + fstream.close(); + br.close(); + return line; + } + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + return null; + } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + Scanner scr = new Scanner(System.in); + ArrayList gamesFull = new ArrayList(); + String line; + + // ------------------------------------------------------------------------------ // + + // Fill full games list + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream("/tmp/games.csv"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + while((line = br.readLine()) != null) { + + Game game = new Game(); + + game.read(line); + gamesFull.add(game); + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Fill production games list + GameList games = new GameList(500); + + line = scr.nextLine(); + + while(true) { + + if(line.compareTo("FIM") == 0) break; + + // ------------------------------------ // + + Game found = gameSearch(gamesFull, Integer.parseInt(line)); + + if(found != null) games.insertEnd(found); + + // ------------------------------------ // + + line = scr.nextLine(); + } + + // ---------------------------------------------------------------------------------------------- // + + // Execute operations + int n_ops = Integer.parseInt(scr.nextLine()); + + for(int x = 0; x < n_ops; x++) { + + line = scr.nextLine(); + + String op = line.substring(0, 2); + int app_id; + + // -------------------------------- // + + // Identify operation + if(op.equals("II")) { + + app_id = Integer.parseInt(line.substring(3, line.length())); + + games.insertBegin(gameSearch(gamesFull, app_id)); + } + else if(op.equals("IF")) { + + app_id = Integer.parseInt(line.substring(3, line.length())); + + games.insertEnd(gameSearch(gamesFull, app_id)); + } + else if(op.equals("I*")) { + + int pos = Integer.parseInt(line.substring(3, line.indexOf(" ", 3))); + app_id = Integer.parseInt(line.substring(line.indexOf(" ", 3) + 1, line.length())); + + games.insert(gameSearch(gamesFull, app_id), pos); + } + else if(op.equals("RI")) System.out.println("(R) " + games.removeBegin().getName()); + else if(op.equals("RF")) System.out.println("(R) " + games.removeEnd().getName()); + else if(op.equals("R*")) { + + int pos = Integer.parseInt(line.substring(3, line.length())); + + System.out.println("(R) " + games.remove(pos).getName()); + } + } + + games.print(); + + // ---------------------------------------------------------------------------------------------- // + + scr.close(); + } + + // ------------------------------------------------------------------------------ // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.in b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.in new file mode 100644 index 0000000..90b8669 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.in @@ -0,0 +1,72 @@ +1189490 +300550 +49800 +1851280 +1112930 +275570 +1276550 +1096530 +690510 +1504570 +1369470 +270130 +336150 +573210 +886470 +1368820 +951530 +247370 +1879330 +1634290 +259570 +941650 +768450 +1347140 +722670 +711540 +450170 +730 +598550 +614090 +809440 +1923860 +559010 +1547380 +554310 +1124090 +292120 +691930 +325420 +663670 +503820 +49600 +49300 +1631930 +1038740 +336760 +64000 +487580 +410890 +363110 +FIM +20 +II 1487390 +II 258520 +II 1165270 +II 298140 +II 213610 +IF 50510 +IF 998660 +IF 1740720 +I* 10 24720 +I* 15 439550 +I* 20 1507410 +RF +RF +RF +RI +RI +R* 10 +RF +RF +RI \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.out b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.out new file mode 100644 index 0000000..e8bb1a6 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/pub.out @@ -0,0 +1,61 @@ +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Faefever +(R) NOBUNAGA'S AMBITION: Tendou with Power Up Kit +(R) Higurashi When They Cry Hou - Ch.2 Watanagashi +(R) Synthesis Universe -Episode 00- +[0] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] +[1] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified Chinese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[2] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[3] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[4] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[5] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[6] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[7] 24720 SPORE™ Galactic Adventures Jun/2009 500000 - 1000000 0 19.99 0 [English, French, German, Italian, Spanish - Spain, Dutch, Russian, Polish, Czech, Hungarian, Finnish, Norwegian, Swedish, Danish] http://www.spore.com/what/ga true false false 88% 15h 32m EA - Maxis [Action, Simulation] +[8] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[9] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[10] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[11] 439550 'n Verlore Verstand Apr/2016 50000 - 100000 0 14.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Swedish, Thai, Traditional Chinese, Turkish, Ukrainian] http://www.skobbejakgames.com true true true 39% 2h 20m Skobbejak Games,Skermunkel [Adventure, Casual, Indie] +[12] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[13] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[14] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[15] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[16] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] +[17] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[18] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[19] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[20] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[21] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[22] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[23] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[24] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[25] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[26] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[27] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[28] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[29] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[30] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[31] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[32] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[33] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[34] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[35] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[36] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[37] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[38] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[39] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[40] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[41] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[42] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[43] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[44] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[45] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[46] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[47] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[48] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[49] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[50] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[51] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/saida.out b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/saida.out new file mode 100644 index 0000000..6a85875 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/saida.out @@ -0,0 +1,61 @@ +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Faefever +(R) NOBUNAGA'S AMBITION: Tendou with Power Up Kit +(R) Higurashi When They Cry Hou - Ch.2 Watanagashi +(R) Synthesis Universe -Episode 00- +[0] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] +[1] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified Chinese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[2] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[3] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[4] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[5] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[6] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[7] 24720 SPORE™ Galactic Adventures Jun/2009 500000 - 1000000 0 19.99 0 [English, French, German, Italian, Spanish - Spain, Dutch, Russian, Polish, Czech, Hungarian, Finnish, Norwegian, Swedish, Danish] http://www.spore.com/what/ga true false false 88% 15h 32m EA - Maxis [Action, Simulation] +[8] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[9] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[10] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[11] 439550 'n Verlore Verstand Apr/2016 50000 - 100000 0 14.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Swedish, Thai, Traditional Chinese, Turkish, Ukrainian] http://www.skobbejakgames.com true true true 39% 2h 20m Skobbejak Games,Skermunkel [Adventure, Casual, Indie] +[12] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[13] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[14] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[15] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[16] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] +[17] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[18] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[19] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[20] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[21] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[22] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[23] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[24] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[25] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[26] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[27] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[28] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[29] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[30] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[31] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[32] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[33] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[34] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[35] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[36] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[37] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[38] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[39] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[40] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[41] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[42] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[43] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[44] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[45] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[46] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[47] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[48] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[49] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[50] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[51] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] From 0cf3b30b14cf91a06f2180208119bf56c4260a27 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:09:17 -0300 Subject: [PATCH 06/13] Adiciona gabarito - TP02Q06 --- .../Game.java | 657 ++++++++++++++++++ .../TP02Q06 - Pilha sequencial em Java/pub.in | 72 ++ .../pub.out | 61 ++ .../saida.out | 61 ++ 4 files changed, 851 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.out create mode 100644 tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/saida.out diff --git a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java new file mode 100644 index 0000000..3228676 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java @@ -0,0 +1,657 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class GameStack { + + private Game[] array; + private int last; + + public GameStack() {} + + public GameStack(int size) { + + array = new Game[size]; + last = 0; + } + + public void insert(Game x) throws Exception { + + if(last + 1 == array.length) throw new Exception("x Insert error: Full stack"); + + array[last++] = x; + } + + public Game remove() throws Exception { + + if(last == 0) throw new Exception("x Remove error: Empty stack"); + return array[--last]; + } + + public void print() { + + for(int i = 0; i < last; i++) { + + System.out.print("[" + i + "] "); + array[i].print(); + } + } +} + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public static Game gameSearch(ArrayList games, int app_id) { + + for(Game game : games) if(game.getAppId() == app_id) return game; + return null; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + // -------------------------------------------------------------------------------- // + + public static String getGameData(String csvFile, int app_id) throws Exception { + + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream(csvFile); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + String line; + + while((line = br.readLine()) != null) { + + String id_s = Integer.toString(app_id); + + if(line.substring(0, line.indexOf(',')).equals(id_s)) { + + fstream.close(); + br.close(); + return line; + } + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + return null; + } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + Scanner scr = new Scanner(System.in); + ArrayList gamesFull = new ArrayList(); + String line; + + // ------------------------------------------------------------------------------ // + + // Fill full games list + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream("/tmp/games.csv"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + while((line = br.readLine()) != null) { + + Game game = new Game(); + + game.read(line); + gamesFull.add(game); + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Fill production games list + GameStack games = new GameStack(500); + + line = scr.nextLine(); + + while(true) { + + if(line.compareTo("FIM") == 0) break; + + // ------------------------------------ // + + Game found = gameSearch(gamesFull, Integer.parseInt(line)); + + if(found != null) games.insert(found); + + // ------------------------------------ // + + line = scr.nextLine(); + } + + // ---------------------------------------------------------------------------------------------- // + + // Execute operations + int n_ops = Integer.parseInt(scr.nextLine()); + + for(int x = 0; x < n_ops; x++) { + + line = scr.nextLine(); + + // -------------------------------- // + + // Identify operation + if(line.charAt(0) == 'I') games.insert(gameSearch(gamesFull, Integer.parseInt(line.substring(2, line.length())))); + else if(line.charAt(0) == 'R') System.out.println("(R) " + games.remove().getName()); + } + + games.print(); + + // ---------------------------------------------------------------------------------------------- // + + scr.close(); + } + + // ------------------------------------------------------------------------------ // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.in b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.in new file mode 100644 index 0000000..c8dcd11 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.in @@ -0,0 +1,72 @@ +1189490 +300550 +49800 +1851280 +1112930 +275570 +1276550 +1096530 +690510 +1504570 +1369470 +270130 +336150 +573210 +886470 +1368820 +951530 +247370 +1879330 +1634290 +259570 +941650 +768450 +1347140 +722670 +711540 +450170 +730 +598550 +614090 +809440 +1923860 +559010 +1547380 +554310 +1124090 +292120 +691930 +325420 +663670 +503820 +49600 +49300 +1631930 +1038740 +336760 +64000 +487580 +410890 +363110 +FIM +20 +I 1487390 +I 258520 +I 1165270 +I 298140 +I 213610 +I 50510 +I 998660 +I 1740720 +I 24720 +I 439550 +I 1507410 +R +R +R +R +R +R +R +R +R \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.out b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.out new file mode 100644 index 0000000..65ddec1 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/pub.out @@ -0,0 +1,61 @@ +(R) Coloring Book for Kids +(R) 'n Verlore Verstand +(R) SPORE™ Galactic Adventures +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Synthesis Universe -Episode 00- +[0] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[1] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[2] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[3] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[4] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[5] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[6] 1276550 Faefever Jul/2020 50000 - 100000 0 0.00 0 [English] null true false false 88% null Monkey Wizard Entertainment [Adventure, Casual, Free to Play, Indie] +[7] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[8] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[9] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[10] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[11] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[12] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[13] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[14] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[15] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[16] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[17] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[18] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[19] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[20] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[21] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[22] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[23] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[24] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[25] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[26] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[27] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[28] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[29] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[30] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[31] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[32] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[33] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[34] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[35] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[36] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[37] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[38] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[39] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[40] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[41] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[42] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[43] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[44] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[45] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[46] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[47] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] +[48] 410890 Higurashi When They Cry Hou - Ch.2 Watanagashi Nov/2015 50000 - 100000 0 3.99 0 [English, Japanese] http://www.mangagamer.org/07thExpansion/ true true true 97% 5h 11m 07th Expansion [Adventure] +[49] 363110 NOBUNAGA'S AMBITION: Tendou with Power Up Kit Jun/2015 50000 - 100000 0 54.99 0 [Japanese] http://www.gamecity.ne.jp/steam/tendo.html true false false 77% null KOEI TECMO GAMES CO., LTD. [Strategy] +[50] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified ChiWnese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[51] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/saida.out b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/saida.out new file mode 100644 index 0000000..0a1006b --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/saida.out @@ -0,0 +1,61 @@ +(R) Coloring Book for Kids +(R) 'n Verlore Verstand +(R) SPORE™ Galactic Adventures +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Synthesis Universe -Episode 00- +[0] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[1] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[2] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[3] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[4] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[5] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[6] 1276550 Faefever Jul/2020 50000 - 100000 0 0.00 0 [English] null true false false 88% null Monkey Wizard Entertainment [Adventure, Casual, Free to Play, Indie] +[7] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[8] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[9] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[10] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[11] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[12] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[13] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[14] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[15] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[16] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[17] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[18] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[19] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[20] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[21] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[22] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[23] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[24] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[25] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[26] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[27] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[28] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[29] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[30] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[31] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[32] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[33] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[34] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[35] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[36] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[37] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[38] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[39] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[40] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[41] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[42] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[43] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[44] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[45] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[46] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[47] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] +[48] 410890 Higurashi When They Cry Hou - Ch.2 Watanagashi Nov/2015 50000 - 100000 0 3.99 0 [English, Japanese] http://www.mangagamer.org/07thExpansion/ true true true 97% 5h 11m 07th Expansion [Adventure] +[49] 363110 NOBUNAGA'S AMBITION: Tendou with Power Up Kit Jun/2015 50000 - 100000 0 54.99 0 [Japanese] http://www.gamecity.ne.jp/steam/tendo.html true false false 77% null KOEI TECMO GAMES CO., LTD. [Strategy] +[50] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified Chinese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[51] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] From e84a042c963090087b7d23d8b0030b3c360aeba9 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:09:27 -0300 Subject: [PATCH 07/13] Adiciona gabarito - TP02Q07 --- .../TP02Q07 - Fila circular em Java/Game.java | 702 ++++++++++++++++++ .../TP02Q07 - Fila circular em Java/pub.in | 67 ++ .../TP02Q07 - Fila circular em Java/pub.out | 81 ++ .../TP02Q07 - Fila circular em Java/saida.out | 81 ++ 4 files changed, 931 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java create mode 100644 tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.out create mode 100644 tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/saida.out diff --git a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java new file mode 100644 index 0000000..f98a763 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java @@ -0,0 +1,702 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.Scanner; + +// ----------------------------------------------------------------------------------------------------------------- // + +class GameQueue { + + private Game[] array; + private int first; + private int last; + + public GameQueue() {} + + public GameQueue(int size) { + + array = new Game[size + 1]; + first = last = 0; + } + + public void insert(Game movie) throws Exception { + + if(((last + 1) % array.length) == first) throw new Exception("x Insert error: Full queue"); + + array[last] = movie; + last = (last + 1) % array.length; + } + + public Game remove() throws Exception { + + if(first == last) throw new Exception("x Remove error: Empty queue"); + + Game resp = array[first]; + first = (first + 1) % array.length; + return resp; + } + + public void print() { + + int c = 0; + + for(int i = first; i != last; i = ((i + 1) % array.length), c++) { + + System.out.print("[" + ((last - first) == 1 ? "0" : c) + "] "); + + array[i].print(); + } + } + + public int length() { return last - first; } +} + +// ----------------------------------------------------------------------------------------------------------------- // + +class Game { + + static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); + + private String name, owners, website, developers; + private ArrayList languages, genres; + private Date release_date; + private int app_id, age, dlcs, avg_playtime; + private float price, upvotes; + private boolean windows, mac, linux; + + public Game() { + + this.name = this.owners = this.website = this.developers = null; + this.languages = new ArrayList(); + this.genres = new ArrayList(); + this.release_date = null; + this.app_id = this.age = this.dlcs = this.avg_playtime = -1; + this.price = this.upvotes = -1; + this.windows = this.mac = this.linux = false; + } + + public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { + + this.name = name; + this.owners = owners; + this.website = website; + this.developers = developers; + this.languages = languages; + this.genres = genres; + this.release_date = release_date; + this.app_id = app_id; + this.age = age; + this.dlcs = dlcs; + this.upvotes = upvotes; + this.avg_playtime = avg_playtime; + this.price = price; + this.windows = windows; + this.mac = mac; + this.linux = linux; + } + + public void setName(String name) { this.name = name; } + public void setOwners(String owners) { this.owners = owners; } + public void setWebsite(String website) { this.website = website; } + public void setDevelopers(String developers) { this.developers = developers; } + public void setLanguages(ArrayList languages) { this.languages = languages; } + public void setGenres(ArrayList genres) { this.genres = genres; } + public void setReleaseDate(Date release_date) { this.release_date = release_date; } + public void setAppId(int app_id) { this.app_id = app_id; } + public void setAge(int age) { this.age = age; } + public void setDlcs(int dlcs) { this.dlcs = dlcs; } + public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } + public void setPrice(float price) { this.price = price; } + public void setUpvotes(float upvotes) { this.upvotes = upvotes; } + public void setWindows(boolean windows) { this.windows = windows; } + public void setMac(boolean mac) { this.mac = mac; } + public void setLinux(boolean linux) { this.linux = linux; } + + public String getName() { return this.name; } + public String getOwners() { return this.owners; } + public String getWebsite() { return this.website; } + public String getDevelopers() { return this.developers; } + public ArrayList getLanguages() { return this.languages; } + public ArrayList getGenres() { return this.genres; } + public Date getReleaseDate() { return this.release_date; } + public int getAppId() { return this.app_id; } + public int getAge() { return this.age; } + public int getDlcs() { return this.dlcs; } + public int getAvgPlaytime() { return this.avg_playtime; } + public float getPrice() { return this.price; } + public float getUpvotes() { return this.upvotes; } + public boolean getWindows() { return this.windows; } + public boolean getMac() { return this.mac; } + public boolean getLinux() { return this.linux; } + + public Game clone() { + + Game cloned = new Game(); + + cloned.name = this.name; + cloned.owners = this.owners; + cloned.website = this.website; + cloned.developers = this.developers; + cloned.languages = this.languages; + cloned.genres = this.genres; + cloned.release_date = this.release_date; + cloned.app_id = this.app_id; + cloned.age = this.age; + cloned.dlcs = this.dlcs; + cloned.avg_playtime = this.avg_playtime; + cloned.price = this.price; + cloned.upvotes = this.upvotes; + cloned.windows = this.windows; + cloned.mac = this.mac; + cloned.linux = this.linux; + + return cloned; + } + + public static Game gameSearch(ArrayList games, int app_id) { + + for(Game game : games) if(game.getAppId() == app_id) return game; + return null; + } + + public void read(String line) { + + char c_search; + int index = 0, atr_index = 0; + + // ---------------------------------- // + + // Find "AppID" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.app_id = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Name" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.name = line.substring(atr_index, index); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find release date + if(line.charAt(atr_index) != ',') { + + SimpleDateFormat df; + + if(line.charAt(atr_index) == '\"') { + + df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); + + atr_index++; + c_search = '\"'; + } + else { + + df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); + + c_search = ','; + } + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + try { this.release_date = df.parse(line.substring(atr_index, index)); } + catch (java.text.ParseException e) { e.printStackTrace(); } + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Owners" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.owners = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Age" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.age = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Price" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.price = Float.parseFloat(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "DLCs" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.dlcs = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Languages" + while(true) { + + index++; + + if(line.charAt(index) == ']') { + + index++; + + if(line.charAt(index) == ',') index++; + else if(line.charAt(index) == '\"') index += 2; + + atr_index = index; + break; + } + else if(line.charAt(index) == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line.charAt(index) == '\'') { + + this.languages.add(line.substring(wordStart, index)); + break; + } + } + } + } + + // ---------------------------------- // + + // Find "Website" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.website = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Windows" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + positives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + negatives = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + this.upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ---------------------------------- // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); + + atr_index = ++index; + break; + } + } + + // ---------------------------------- // + + // Find "Developers" + if(line.charAt(atr_index) != ',') { + + if(line.charAt(atr_index) == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line.charAt(index) == c_search) { + + this.developers = line.substring(atr_index, index); + + atr_index = ++index; + break; + } + } + } + else atr_index = ++index; + + // ---------------------------------- // + + // Find "Genres" + if(index < line.length() - 1) { + + if(line.charAt(index) == ',') atr_index = ++index; + if(line.charAt(atr_index) == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line.charAt(index) == ',') { + + this.genres.add(line.substring(atr_index, index)); + + atr_index = ++index; + } + else if(line.charAt(index) == '\"') { + + this.genres.add(line.substring(atr_index, line.length() - 1)); + break; + } + } + } + else this.genres.add(line.substring(atr_index, line.length())); + } + + // -------------------------------------------------------------------------------- // + } + + public void print() { + + String avg_pt = null; + + if(this.avg_playtime == 0) avg_pt = "null "; + else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; + else { + + if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; + else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; + } + + DecimalFormat df = new DecimalFormat("##"); + + System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); + } + + // -------------------------------------------------------------------------------- // + + public static String getGameData(String csvFile, int app_id) throws Exception { + + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream(csvFile); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + String line; + + while((line = br.readLine()) != null) { + + String id_s = Integer.toString(app_id); + + if(line.substring(0, line.indexOf(',')).equals(id_s)) { + + fstream.close(); + br.close(); + return line; + } + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + return null; + } + + // -------------------------------------------------------------------------------------- // + + public static void main(String[] args) throws Exception { + + Scanner scr = new Scanner(System.in); + ArrayList gamesFull = new ArrayList(); + String line; + + // ------------------------------------------------------------------------------ // + + // Fill full games list + try { + + // Read CSV file + FileInputStream fstream = new FileInputStream("/tmp/games.csv"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + + // ------------------------------------ // + + // Start to explode CSV file + while((line = br.readLine()) != null) { + + Game game = new Game(); + + game.read(line); + gamesFull.add(game); + } + + // Close CSV file + fstream.close(); + } + catch(IOException e) { e.printStackTrace(); } + + // ---------------------------------------------------------------------------------------------- // + + // Fill production games list + GameQueue games = new GameQueue(5); + float total_avgPt = 0, c = 0; + + line = scr.nextLine(); + + while(true) { + + if(line.compareTo("FIM") == 0) break; + + // ------------------------------------ // + + Game found = gameSearch(gamesFull, Integer.parseInt(line)); + + if(found != null) { + + try { games.insert(found); } + catch(java.lang.Exception e) { + + total_avgPt -= games.remove().getAvgPlaytime(); + c--; + + games.insert(found); + } + + // Print playtime avg + total_avgPt += found.getAvgPlaytime(); + + System.out.println(Math.round(total_avgPt / ++c)); + } + + // ------------------------------------ // + + line = scr.nextLine(); + } + + // ---------------------------------------------------------------------------------------------- // + + // Execute operations + int n_ops = Integer.parseInt(scr.nextLine()); + + for(int x = 0; x < n_ops; x++) { + + line = scr.nextLine(); + + // -------------------------------- // + + System.out.println(line); + + // Identify operation + if(line.charAt(0) == 'I') { + + Game found = gameSearch(gamesFull, Integer.parseInt(line.substring(2, line.length()))); + + try { games.insert(found); } + catch(java.lang.Exception e) { + + total_avgPt -= games.remove().getAvgPlaytime(); + c--; + + games.insert(found); + } + + // Print playtime avg + total_avgPt += found.getAvgPlaytime(); + + System.out.println(Math.round(total_avgPt / ++c)); + } + else if(line.charAt(0) == 'R') System.out.println("(R) " + games.remove().getName()); + } + + games.print(); + + // ---------------------------------------------------------------------------------------------- // + + scr.close(); + } + + // ------------------------------------------------------------------------------ // +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.in b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.in new file mode 100644 index 0000000..cdedafd --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.in @@ -0,0 +1,67 @@ +1189490 +300550 +49800 +1851280 +1112930 +275570 +1276550 +1096530 +690510 +1504570 +1369470 +270130 +336150 +573210 +886470 +1368820 +951530 +247370 +1879330 +1634290 +259570 +941650 +768450 +1347140 +722670 +711540 +450170 +730 +598550 +614090 +809440 +1923860 +559010 +1547380 +554310 +1124090 +292120 +691930 +325420 +663670 +503820 +49600 +49300 +1631930 +1038740 +336760 +64000 +487580 +410890 +363110 +FIM +15 +I 1487390 +I 258520 +I 1165270 +I 298140 +I 213610 +I 50510 +I 998660 +I 1740720 +I 24720 +I 439550 +I 1507410 +R +R +R +R \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.out b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.out new file mode 100644 index 0000000..83abd24 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/pub.out @@ -0,0 +1,81 @@ +2019 +1460 +978 +809 +647 +284 +104 +556 +833 +1165 +1125 +1132 +677 +388 +55 +70 +63 +103 +55 +55 +94 +133 +93 +93 +114 +75 +90 +6187 +6324 +6358 +6346 +6292 +196 +59 +57 +54 +401 +407 +476 +450 +503 +246 +381 +312 +323 +271 +300 +199 +261 +223 +I 1487390 +341 +I 258520 +259 +I 1165270 +219 +I 298140 +160 +I 213610 +272 +I 50510 +158 +I 998660 +120 +I 1740720 +188 +I 24720 +371 +I 439550 +287 +I 1507410 +282 +R +(R) Sopwith VR +R +(R) Have a Nice Death +R +(R) SPORE™ Galactic Adventures +R +(R) 'n Verlore Verstand +[0] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/saida.out b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/saida.out new file mode 100644 index 0000000..406e14f --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/saida.out @@ -0,0 +1,81 @@ +2019 +1460 +978 +809 +647 +284 +104 +556 +833 +1165 +1125 +1132 +677 +388 +55 +70 +63 +103 +55 +55 +94 +133 +93 +93 +114 +75 +90 +6187 +6324 +6358 +6346 +6292 +196 +59 +57 +54 +401 +407 +476 +450 +503 +246 +381 +312 +323 +271 +300 +199 +261 +223 +I 1487390 +341 +I 258520 +259 +I 1165270 +219 +I 298140 +160 +I 213610 +272 +I 50510 +158 +I 998660 +120 +I 1740720 +188 +I 24720 +371 +I 439550 +287 +I 1507410 +282 +R +(R) Sopwith VR +R +(R) Have a Nice Death +R +(R) SPORE™ Galactic Adventures +R +(R) 'n Verlore Verstand +[0] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] From bc0509be44da03fc6da5d2fe1ca69c759dbe6eee Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:09:36 -0300 Subject: [PATCH 08/13] Adiciona gabarito - TP02Q08 --- .../Game_Linux.c | 859 ++++++++++++++++++ .../TP02Q08 - Lista sequencial em C/WSL_Game | Bin 0 -> 26208 bytes .../WSL_Game.c | 858 +++++++++++++++++ .../TP02Q08 - Lista sequencial em C/pub.in | 72 ++ .../TP02Q08 - Lista sequencial em C/pub.out | 61 ++ .../TP02Q08 - Lista sequencial em C/saida.out | 61 ++ 6 files changed, 1911 insertions(+) create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.in create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.out create mode 100644 tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/saida.out diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c new file mode 100644 index 0000000..8554cb3 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c @@ -0,0 +1,859 @@ +// -------------------------------------------------------------------------------- // + +// Includes +#include +#include +#include +#include +#include + +// -------------------------------------------------------------------------------- // + +// Definitions +#define MAX_GAMES 500 +#define MAX_FIELD_SIZE 250 +#define MAX_STRING_ARRAY_SIZE 100 + +// -------------------------------------------------------------------------------- // + +// Structs +typedef struct { + + int year, + month; +} Date; + +typedef struct { + + char name[MAX_FIELD_SIZE], + owners[MAX_FIELD_SIZE], + website[MAX_FIELD_SIZE], + developers[MAX_FIELD_SIZE], + languages[MAX_STRING_ARRAY_SIZE][30], + genres[MAX_STRING_ARRAY_SIZE][30]; + + Date release_date; + int app_id, age, dlcs, avg_playtime, count_languages, count_genres; + float price, upvotes; + bool windows_os, mac_os, linux_os; + +} Game; + +// -------------------------------------------------------------------------------- // + +// Global variables +Game games[MAX_GAMES]; +int n = 0; + +Game gamesFull[5000]; +int x = 0; + +// -------------------------------------------------------------------------------- // + +// Functions +bool isFim(char* s) { return s[0] == 'F' && s[1] == 'I' && s[2] == 'M'; } + +void substring(char *string, char *string_start, int length) { + + strncpy(string, string_start, length); + string[length] = '\0'; +} + +char *getMonthName(int month) { + + switch(month) { + + case 1: return "Jan"; break; + case 2: return "Feb"; break; + case 3: return "Mar"; break; + case 4: return "Apr"; break; + case 5: return "May"; break; + case 6: return "Jun"; break; + case 7: return "Jul"; break; + case 8: return "Aug"; break; + case 9: return "Sep"; break; + case 10: return "Oct"; break; + case 11: return "Nov"; break; + case 12: return "Dec"; break; + + default: return "N/A"; break; + } +} + +int getMonthNumber(char* month) { + + if(!strcmp(month, "Jan")) return 1; + else if(!strcmp(month, "Feb")) return 2; + else if(!strcmp(month, "Mar")) return 3; + else if(!strcmp(month, "Apr")) return 4; + else if(!strcmp(month, "May")) return 5; + else if(!strcmp(month, "Jun")) return 6; + else if(!strcmp(month, "Jul")) return 7; + else if(!strcmp(month, "Aug")) return 8; + else if(!strcmp(month, "Sep")) return 9; + else if(!strcmp(month, "Oct")) return 10; + else if(!strcmp(month, "Nov")) return 11; + else if(!strcmp(month, "Dec")) return 12; +} + +// -------------------------------------------------------------------------------- // + +// Class game functions +void game_start(Game *game) { + + strcpy(game -> name, ""); + strcpy(game -> owners, ""); + strcpy(game -> website, ""); + strcpy(game -> developers, ""); + + for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) { + + strcpy(game -> languages[i], ""); + strcpy(game -> genres[i], ""); + } + + game -> release_date.month = -1; + game -> release_date.year = -1; + game -> app_id = -1; + game -> age = -1; + game -> dlcs = -1; + game -> avg_playtime = -1; + game -> price = -1; + game -> upvotes = -1; + game -> windows_os = false; + game -> mac_os = false; + game -> linux_os = false; + + game -> count_languages = 0; + game -> count_genres = 0; +} + +void game_print(Game *game) { + + int hours = game -> avg_playtime / 60, + minutes = game -> avg_playtime % 60; + + printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs); + + for(int i = 0; i < game -> count_languages; i++) { + + printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : ""); + } + + printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false"); + + if(isnan(game -> upvotes)) printf("0.0%% "); + else printf("%.0f%% ", game -> upvotes); + + if(hours > 0) + { + printf("%ih ", hours); + + if(minutes > 0) printf("%im ", minutes); + } + else { + + if(minutes > 0) printf("%im ", minutes); + else printf("null "); + } + + printf("%s [", game -> developers); + + for(int i = 0; i < game -> count_genres; i++) { + + printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : ""); + } + + printf("]\n"); +} + +Game game_clone(Game *game) { + + Game cloned; + + strcpy(cloned.name, game -> name); + strcpy(cloned.owners, game -> owners); + strcpy(cloned.website, game -> website); + strcpy(cloned.developers, game -> developers); + + for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]); + for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]); + + cloned.release_date.month = game -> release_date.month; + cloned.release_date.year = game -> release_date.year; + cloned.app_id = game -> app_id; + cloned.age = game -> age; + cloned.dlcs = game -> dlcs; + cloned.avg_playtime = game -> avg_playtime; + cloned.price = game -> price; + cloned.upvotes = game -> upvotes; + cloned.windows_os = game -> windows_os; + cloned.mac_os = game -> mac_os; + cloned.linux_os = game -> linux_os; + return cloned; +} + +void game_read(Game *game, char *line) { + + char c_search, sub[MAX_FIELD_SIZE]; + int index = 0, atr_index = 0; + + // ------------------------------------------------------------ // + + // Find "AppID" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> app_id = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Name" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> name, sub); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else { + + strcpy(game -> name, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find release date + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + + char subDate[10]; + + substring(subDate, &sub[0], 3); + + game -> release_date.month = getMonthNumber(subDate); + + if(c_search == ',') { + + substring(subDate, &sub[4], 4); + + game -> release_date.year = atoi(subDate); + + index++; + } + else if(c_search == '\"') { + + int nmbSpace = 0; + + for(int i = 0; ; i++) { + + if(sub[i] == ' ') nmbSpace++; + + if(nmbSpace == 2) { + + i++; + + substring(subDate, &sub[i], 4); + + game -> release_date.year = atoi(subDate); + break; + } + } + + index += 2; + } + + atr_index = index; + break; + } + } + } + else { + + game -> release_date.month = 0; + game -> release_date.year = 0; + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Owners" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> owners, sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Age" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> age = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Price" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> price = atof(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "DLCs" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> dlcs = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Languages" + while(true) { + + index++; + + if(line[index] == ']') { + + index++; + + if(line[index] == ',') index++; + else if(line[index] == '\"') index += 2; + + atr_index = index; + break; + } + else if(line[index] == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line[index] == '\'') { + + substring(sub, &line[wordStart], index - wordStart); + strcpy(game -> languages[game -> count_languages++], sub); + break; + } + } + } + } + + // ------------------------------------------------------------ // + + // Find "Website" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> website, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> website, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Windows" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> windows_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> mac_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> linux_os = true; + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + positives = atoi(sub); + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + negatives = atoi(sub); + atr_index = ++index; + break; + } + } + + game -> upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ------------------------------------------------------------ // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> avg_playtime = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Developers" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> developers, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> developers, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Genres" + if(index < strlen(line) - 1) { + + if(line[index] == ',') atr_index = ++index; + + if(line[atr_index] == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> genres[game -> count_genres++], sub); + + atr_index = ++index; + } + else if(line[index] == '\"') { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0'; + + strcpy(game -> genres[game -> count_genres++], sub); + break; + } + } + } + else { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + sub[strlen(line) - 2 - atr_index] = '\0'; + + strcpy(game -> genres[game -> count_genres++], sub); + } + } +} + +// -------------------------------------------------------------------------------- // + +// Functions - List +void list_insertBegin(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + for(int i = n; i > 0; i--) games[i] = games[i - 1]; + + games[0] = x; + n++; +} + +void list_insertEnd(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + games[n++] = x; +} + +void list_insert(Game x, int pos) { + + if(n >= MAX_GAMES || (pos < 0 || pos > n)) { + + printf("Insert error: %s", n >= MAX_GAMES ? "MAX_GAMES reached" : "Invalid position"); + exit(1); + } + + for(int i = n; i > pos; i--) games[i] = games[i-1]; + + games[pos] = x; + n++; +} + +Game list_removeBegin() { + + Game resp; + + if(n == 0) { + + printf("Remove error: Empty list"); + exit(1); + } + + resp = games[0]; + n--; + + for(int i = 0; i < n; i++) games[i] = games[i + 1]; + return resp; +} + +Game list_removeEnd() { + + if(n == 0) { + + printf("Remove error: Empty list"); + exit(1); + } + return games[--n]; +} + +Game list_remove(int pos) { + + Game resp; + + if(n >= MAX_GAMES || (pos < 0 || pos > n)) { + + printf("Insert error: %s!", n == 0 ? "Empty list" : "Invalid position"); + exit(1); + } + + resp = games[pos]; + n--; + + for(int i = pos; i < n; i++) games[i] = games[i+1]; + return resp; +} + +void list_print() { + + for(int i = 0; i < n; i++) { + + printf("[%i] ", i); + game_print(&games[i]); + } +} + +Game game_search(int app_id) { + + for(int i = 0; i < x; i++) { + + if(gamesFull[i].app_id == app_id) return gamesFull[i]; + } + + Game game; + game.app_id = -1; + return game; +} + +// ---------------------------------------------------------------------------------------------------------- // + +int main() { + + // ---------------------------------------------------------------------------------------- // + + // Fill full games list + FILE *fp; + char *line = NULL; + size_t len = 0; + size_t read; + + fp = fopen("/tmp/games.csv", "r"); + + if(fp == NULL) exit(EXIT_FAILURE); + + // -------------------------------------- // + + while((read = getline(&line, &len, fp)) != -1) { + + Game game; + + game_start(&game); + game_read(&game, line); + + gamesFull[x++] = game; + } + + fclose(fp); + + if(line) free(line); + + // ---------------------------------------------------------------------------------------- // + + char line_in[100]; + + // Fill production games list + scanf(" %[^\n]", line_in); + + while(true) { + + if(isFim(line_in)) break; + + // -------------------------- // + + int app_id = atoi(line_in); + + Game found = game_search(app_id); + + if(found.app_id != -1) list_insertEnd(found); + + // -------------------------- // + + scanf(" %[^\n]", line_in); + } + + // ---------------------------------------------------------------------------------------- // + + // Execute operations + int n_ops; + scanf("%i", &n_ops); + + for(int i = 0; i < n_ops; i++) { + + scanf(" %[^\n]", line_in); + + Game game; + char params[10]; + + if(line_in[0] == 'I') { + + substring(params, &line_in[3], strlen(line_in) - 3); + + if(line_in[1] == 'I') list_insertBegin(game_search(atoi(params))); + else if(line_in[1] == 'F') list_insertEnd(game_search(atoi(params))); + else if(line_in[1] == '*') { + + char appId[10], pos[10]; + int i = 0; + + while(true) { + + if(params[i] == ' ') { + + substring(pos, ¶ms[0], i); + substring(appId, ¶ms[i + 1], strlen(params) - i - 1); + break; + } + else i++; + } + + list_insert(game_search(atoi(appId)), atoi(pos)); + } + } + else if(line_in[0] == 'R') { + + if(line_in[1] == 'I') printf("(R) %s\n", list_removeBegin().name); + else if(line_in[1] == 'F') printf("(R) %s\n", list_removeEnd().name); + else if(line_in[1] == '*') { + + substring(params, &line_in[3], strlen(line_in) - 3); + + printf("(R) %s\n", list_remove(atoi(params)).name); + } + } + } + + list_print(); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game new file mode 100644 index 0000000000000000000000000000000000000000..498668a2dc5c58a68382de1586ba84632d2316f2 GIT binary patch literal 26208 zcmeHQ3w%_?xu4Cl5D~ILNyYcdC6#9g2nY%_0XCdiUh+_s#}bl-tmb91i-7_L*R@%f zEvZ*p{MDZqf4yyOtF5-xVk_4~ki=fpfT&ohMyt2G4QdQ}8xY<5|K@S_oReM97QOx5 z%h9vn%=em^Z@&4?oSBp1cK7U}44aLq%g(;RDCasyUK>S|HE@6F< z@56C|ULXLd;yRRJhM5v?2PC;6lt=+D5@@ENsv$v=OLr|fOHdSK*&brPEs=6dq@03X(hv$N zdy-A)o-FNYg)Y$Oa`9irta3}FoE6TL{0dSTbS-?>U-tKuH($zaFBE#LaF0MU1yy<1 zL5}S5c`wz?3uJle`eCQ+2L+{h+1Lu-s!0>ZR+NpY@Kpus$J9@rG-lF-yt?YV@w^ID zFDiq&f7aZ^3~HJQC(X$FVzA5;{nwoz+g8l$8nNb9-;`?4PwUqY|3OgcpfZVvE|Qm3 z;(1Dw9^w)0-^}rZqietSg-Vf1{d*tKawwY^MyJ952k(bz-q`_aC2LJ6e_=Yt2KLYQ&ngZHJulkQadbuR#ew{S&6@THU0S58m}KC!3(+4`V!A-UsXwkZ@rfn zT3G`u)q_;l`aP8;J}9X5dfBYm#nWea#^+tBrzYsB@p%)Or+CpEPnoyYyT(`N_tq|& zGozxq%Dbp!RRtBarn0(9s`Lofl#DP!1|Ku@EB>=fC@6h+PK+xXMwkr}Dn6X&^9`iP z`GCX?=6O4NNah0<`0zx@V8241E)~aB{AA|}{CpXw6~0+^ZstlsS9p~_L<0mDjcFA# zDBoeg)0k6N%z#IQ^{dN(msR1k9s^#*3L>nO_#d?)YXsPZNgj_^o=LCJNp05tp8(6{yj_nT}%E?mi)_>{PULlvzGiWOa5_Ve%yP-;r%PL@Y`DOov!(dW=9=Q zjD)L12VTR$w3)*gOXS=Gk&l|R=(H!1(4vlC5t!2B&w*=IQ5vpwR-(gsX#=dwc1sBU zFz26m2Z0fvY2hxd<^5~4mL9ui+pF#W%s&_k+)_biqGL7h2PIGb*D!4{$Sg2wu@;;* zl#*KbUHqO8aBHmP(?miMP>8L4FJn#5=_2XC$#9`5S0Vd2J!YD>64*t z*P=PMAr0AYBsxHtgiPnnNQ|RI2@<0zu>^_BDKQU;p_C{>;$linLt+ReCLnPxB}O5U zMTwzEoJEQAk?2E-Y$Ot+km!fRaU@I)&Q_+=q7xqhk=nQ%Z45OB`g23Ym%&`z0MUs} zl3}W1pqLTAI>}Hc87@=|6hz_|BpI%k498E%A}FfFkCBC_&!Q8jNQT!G1BIFRp(Mja zl3}M}ptuwNZIU5D{*6|AUolW1ihnQ3@U~=FD;WCiq{!4+FDuX{sY?`<;#B8NlKKlt zy-HF06LqSj-YcmWDeBooy+l&iOX_Ez@V58cIe@4v={)F)7%;^e&zo0G{qRI;_9hLVz}wZSiQO-UawyuNU8;i83jT+-NXLs4y!2C59%%Xc8$ z*x0DG{MBW9rscS!rRUNS&xG5!uwl}Iqn;=Km3RA;=_@}hi^GBbp#|1lf=x( z4r(+d(H!2iqt2V!x}AgOG;@vH$wHKx9etEKR|q{sHsy3~YxwRXa1kxsqD25Yv;IYD>3EvX*5H{3&6=MxRo zF?ZsLfyc}Tmy4nXb|N9k)P;ha(=N$5`;uhpY(aKBCdrORI62U!ZQe@*pcu6c@7Kc5 zpz+&55|z5YhkGYCI{A(>ulZZ&f+M7JtOrNuWmFC77~(<4V2Dif5epQv*bQI_Zal;` zO^CP;@m4R^#jobH!)(*6i2E?7eM6^RN~*^OH-b7uQC&LKM$|zl=o}sO{@+AxH3yAi zVc_FmS8Ztrwbgx)jNQ3ZSed+wUk zlpRQ_r??Mp_#SHbE%3x_AY(q@?O0m4tZ;eZisV4jHXoq{I4w9}7(@C|#5OIwYsow0 zsgKVGDAOW+a^WaIyL-kpYmse))uN#q&hrWd<$L~{+8z>wCO!ltod-KD%(*H|T-5JM zi-TtbSCNT}+fwNghUL0k;A#z(qYB)lYa%?IHdur=H;3qJU~t1xD9u^?x_F1-J! z_9Kk3o-*wU;ktfD?3$0bi&A09NAp5>{1WoR@UDk2Glj?R05E!dY+Q3|XeW^5X04&8 zWGcvUwg?B*eUT7JV)93`(b0i71!WW$2tO0ykVdrPYe926NJ8}ReDtu6X^kB?ifm*X z)hT=jb(*QXFxS?klv)dS-gy9ZO+y_T$PRLG+uqP`p?+v*Kam)1D#F^N$(%Xx`WI~0 zI$?Bf+vqmYUOs$Fx)X_pT~vY5fwN@Eo!J62G|*3AGDK;jxt+scJ5tojssa@idkgxc zGD@0Ok9OX<58a%G`qkRROMM%Sa$`h8ub@T0qv^DCgjt-*(G*xma05z5pwX?2cCGT3 zsMZHbu7)PvQVlb!x#L5FKT%MSCXYV^5ovX2=m*HOhMG|$B#_!8QxTrhwmYA=(?Qjq z>Y^SZK3i}XfsDWnLC#~-L@z4|ElQEDSM64z_a&Md`A(Omc1^PXI|oR$@pYJ}n!I76 z@&-P)qWbCxY9C#)jYcsO%If2P$FRMR+m*W|=H>FaM<(K7=+)Tz59rB3;X{TB;man} zX{g3IR1FnRT4VR3R6Tl7h&Pq@UQob2TF zygd0-B4&Cj5j@FL>37_C+`Yw&C#qorBBIgV^bSG|P5E*vh6K&G=3~AkpLBRKzZzR} z1T)ci7zO`RMB`WABmYn%Sk6feBY0=0#jNsaG*Suisq0CfNhj}>FFscoMpc$JjZS>v z0t))AvD;BmtnOsVdWm;zo2l$CXXI}~hbF7zl-23_tEDE~Bbo!ihY$~x$!V{r_;&_3%}{c?Kd6ExaT_C{WId+M?gi>Ow&G?yK9j%qf8`3 z%(ix5@P56b#SqNtRomoSy+Ym>_v_i_>b?*|?bRHZUPMgg35%U1g3`xR{}d4>0JE!L z5p9z1vxW$B{a;QMVMykr5k@^Eu)ZZ;L*QxGK&^)51#QZ1XYepIC?@OcLg3sKhD~QV zXXqH7O!5uFB-h&k#Dr25JL>bk2+iWXE+0Acj%$46P(H;YN4{Fq%YkO2_eg_vd)`fH z-FSii^z2pfq0Z1yzAmcU@+g$3mpEEUgjvITdznbgb*b!dx15HrqfSuuX^s6HdZgN!}}_*{t&_1F>2VvD+ah;X?x#8p!h{S;zPd^-k| z!N1-F^6#>V_rG8S@x(nXwfh>?PQy~O@ooP)AhpeV=-qy)VXZ58Bs=1Gay(^A{B9b7kpv&iOvmJU60Pk_RtAz^7xwh`b2c%R#3Il16XSo zh=H33fh8N;ALJ6ocrBbSRxacc#w+F}jC#3*fmMuWY%N&A2)DJw?BQm&YLZjti-X=;G`rYiI``+zL)w=^%IOiS!R+rd5EK!3BLHj+e(_lww-w*oTB+ zBP-(gJrK#(`_56VANyz3`VdkP$G?IvI^Pz~xf=;X!*jkzd79aw9%8NLA8x2&U7r^8 z!yAu89OtTf-aaU}@d&FwJK|tKO>rODbalk>alUE=7Ns4#2Z^Oq$37&)%Iix=iEh3A zZPl=ck%~Be2hsH1x)W4WxBi3>r@dR@Ojo;)IJeeQ7{bC?(y?+T@d8h)eIt%%$4Y;A z3JHThq+k6tE`nj%H{!Shl9*u9nE7_LGVZYsW!!mhk&B8&;b_jSU_P~%j-^^5mO8$U zL~<21PJ63jAr&4dS5%W0nm8ETrarP0;`H_rUs<(999#0>b3EhR;uBAWuV%e+>zh1G zn%65aIGt!2yNH9;XGI*Dz)lHKcGKjD<2ZJ|;fFNthoI%1 zwEul@AX>q9M6z{btaw8i<2Oh}xIDGIUB>Gdphr0@V)iLR>K)+c#$1PlP#5NoaVmH9 zQbEQi#Ues{Iqv!=Y@`3LxNFDZH14YQvL_?t@g8azpxpH-$e5q1Is7{TJX|n=JqOX6 z_N>wW)F}6f4ZE5?SL90RTZZUzj~-nN10g42pM>u?vW1@oZpNDj4ZU8$XW(tIiKlbG zbgm1kP?L*oa@BXs5NfdJi(i^6eKis1;@9=Ul0$gm?CAZ&*h)|g`-HQn91eT{#PGh1 z8OJa-OSINd$BkkE8OfMRV!qU$hTF8e0b+mtBlLwsU7%{gT?Cjj^h0!u2wr`tBGFJg z<{{(=G6)vcCcNI!C^Zfh z;`I`{I9H2y^@w&6NH{~|MIUk@wC4M-QEP-0zQS^Uy=H!P*)+2nwvp;_uKrk!x&?Z2~DAI!r>swvla=5u2_*#-}Zj zP(G>}>`C}%@~;p#A8Dlbt#Ak5m*?FfqvWe7mQOsf8FxIA8SYP$PMUni?xlUK&3l?i zP;bePGF40ZqYnJrza+6yC%$(G=6b^2Ftykjx`MXQWyJ%)2Qe|mn;mQu)$FMMDl)1t zdJZfCvCa4->=vEU8rupf5(%-JR3lsH^9%aE($X^GIAzOr(vFH~S^O^4ju%;ED)J&# zWK%#DIX6v_#Bs_ZXVK=5Eb?4cHeqCf5yw>$}P(R~-i_MK=(~scaH{Q|ygOt9*)f26_8!@sIH0&E02#GxRR-(kJjO zUFgw=d1b_CvWcx$fupZ&vJu4uY1Aul&z~yUqQE%F7PJ{;{rKuY$C2zoe8(naKX@5m zgw*gtM+VB3?>-6aNqqN4SO@xqH@C)K2RHXw3Rq%bJ|;>Ov5-n!rI)yobn~%}IWh%< zDLmuc@^2W-qEdA|GNnb9)BEv7{6h}xhL3|Ra6QlMUY+N>^iDJxuLbnMWZ@07qtkxx z!e>d>7l&UdTwEOfxNuQn_{3r@I_6=Z7tS8>DRo|K-b>KX@~Pc_>A2VB_oK7J-Lu2* z&kX;iFfsT|Ew~$NPk##hmA+qIx?FsAQs~*eI$0oK=?vtV>x>2dpIN|$ zzip)J+L9_(zjdn4X zTbEnM{IvluTU}CtKS5nC1mrKv&&$uvb+O#M{M8)#%8~I^y7(6wNY+8ka<+)%=_;waishUFY-rs;ew2P`L%( z%IdXVrPEzm<6q~hz#p(OL(*JsZrx>UX|8X%i`BBR{>qxMYf37;b$O+AYndx|>5Bf# z(F8Vp!3Z=Gb5(pE@wDwi`_+4pqQ66Kd?AtOA^2h<;lg6!cEHJijhL%<0DtTLL}EVj zzXhxTJPz0d_|Snw;!(gW4<-`rfLjoNy8vIt19S+w{Q%~?lL1?>U$hKxH@2}h0G461 z?|#6Suoe3h;2qfBJ`6bS!$jf)!J~=9MVRG90jC0fggL`9z!)B~4S-890ciuIOa1Ms zZT$jftIxJwIG|r9)s66Uw!;pz1uH3x&FqH-9>#{@o`AdYdCWAx$Fj1EvW8siJo~oH z26oK_SB<=4*ic}({4&6muniX^BrekH$GrsjE<(tQ%G!eaeAujraPF+^yE0}B?7I;a zLYC+cfcKzJ7Mtj^ zIi1=)8u)uLMvBRHO8%SQu}AxCaRmF?C)%Ni^eh73>p)NIWD05px^Ua zBJqLKK-YqH`x{QZuG_)09J@prfVz&1V>*2&@Yi5->_L!|^zAzR5a`XIR~zN+tM#__ z0Plo9{nAALu}&xddjNj+OOyT|>-xzr$H4!1cv7~o|4o-)0{Xx%_?=09p)Ow!dNJs0 zOy#fO@-E112fYdY9LLl~Z(j*)^t6NPmr~45qRw1r zEO5pGXDo2W0%t66#sdF`EFceGQRlwUw1X}M2Z*eG@C-JO_|-F2KzuXCFLk~Q7Bl%p zb5pwTi5tJvIWsg5q)X91{wz^V`5kiJt>zldGJ*9beyMpmf6V~KE-OfXUP#vv0a%WN z3P`m~^9T&4M*J$5@-*+JtDgY;y@irp5~1+X0d^W4XeED)xAmMxoS4vnTVS|KC67G=j zQ3;zRY?rV@!Y&CJzCEBTTSAfh{J)ti1@EjGGp=$CU%V<%^(Ur5=aw?`HnKO!>JP-;b&B zV8&-M(1Z%>0OoD~%YDwj&z4QsPzAOv+Gr>cc+dyB0|--o=s0K&Q-yDU27k@;Sc2g1=1S zReV=6S0Z6E)JKLxMr#bV6n3bTdepgLO3ymZ-`k$sflpQcbnW^f*E5*;-AZ#3rqc5m zC+GC)uV=WP-u?BTl3zWil=e4xqPPEi$o2H@UwS9bpkA=}e?K(r93Z>ob5T9V&f|Dh zS`vI369TZH;&SJlzfI~XkQ1J* zXg^*54!nz}%s;;deo)5wOg&!}wOQ)9V7$QmQW9PyezIJFK&bwGL-H@p6Zi)u|9cXD zk8BrTn*{B+#5c%sTduOWiA3wJj8NuxZER`RcxdR($I$4Y#T)N?}C zr&`+KGKn8X3)i^#S|;FV;7PyLpJ^UI_1Q9svopRPhvYQi$!}ek2!iY8^HCF=lgjx8 zukrV$H28`%_`A~Je~H?Fz)Z)np;hWsQ!^LsuZW{VPkP3vI5O2N zN~fcmF?0y38RPMmmH12KA*p5(-`Sx`;S^Of#d_juk~%@O%E$MrM61MUtVtHV>72mo z0;^DjuWAhwE%lbvmX<5)B~M{B%X3z2e3da@U6HR6?9>WrCNf23jYYugpHp4sFP|Hz zT;;6=zxhN~Pgz~Hr@W-945zgky2V`uXDFTry=A^CPoNIFY@8~ZM^v08EA*n5RHdoQ z$@@fuxYHZO1X?uS<5^W#C#%iRn&mbx!e3~Mb8pR!pwny381u2XN!pd_klQ4R%uWaD znlT>FqB%3vIG`hJQ=Us}J}K9%!C)@N^6J)A`b$;;`fCL&S1BCH>#eO}c~#YZZ{C`! zKweEPPWG+!uQQ-l1$;QB+E*q~h0}}2_)FF>&R$+pSI+Xv)>WYh0sXatvesK$N4uMx zO=dix)p{#RNI<4)D*P;u_e&mU}fb;y`dSofQfV-Lxi9Bz)3@GJg(57-i zhlngfLZwkuNu>|UggAPZ!UqeoU3bC870=*V_O0TjX6*PC>3*sw7}h&wgT+ zm+KEM2^GImq4EkoYLQp#7YcSMK?#+df=^oH)jU+emz4upB>Ao?U#N1;m& z3tgY;|DS_KEJ|Lj6KV5EN`43_lKfYdt6*OU8|B$b$vj^`RgT2!<*Ph>vq8F4`L30M zk}c(3!_DtYE`q2xzd@We}(5h~vi6!BXi%h%+>Ilb=EtC(uHioZlw ibr+K2xA8^+Kd}&1xr&#DxrK$3g3ATR1r`BImi-TTDC_|M literal 0 HcmV?d00001 diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c new file mode 100644 index 0000000..e85add2 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c @@ -0,0 +1,858 @@ +// -------------------------------------------------------------------------------- // + +// Includes +#include +#include +#include +#include +#include + +// -------------------------------------------------------------------------------- // + +// Definitions +#define MAX_GAMES 500 +#define MAX_FIELD_SIZE 250 +#define MAX_STRING_ARRAY_SIZE 100 + +// -------------------------------------------------------------------------------- // + +// Structs +typedef struct { + + int year, + month; +} Date; + +typedef struct { + + char name[MAX_FIELD_SIZE], + owners[MAX_FIELD_SIZE], + website[MAX_FIELD_SIZE], + developers[MAX_FIELD_SIZE], + languages[MAX_STRING_ARRAY_SIZE][30], + genres[MAX_STRING_ARRAY_SIZE][30]; + + Date release_date; + int app_id, age, dlcs, avg_playtime, count_languages, count_genres; + float price, upvotes; + bool windows_os, mac_os, linux_os; + +} Game; + +// -------------------------------------------------------------------------------- // + +// Global variables +Game games[MAX_GAMES]; +int n = 0; + +Game gamesFull[5000]; +int x = 0; + +// -------------------------------------------------------------------------------- // + +// Functions +bool isFim(char* s) { return s[0] == 'F' && s[1] == 'I' && s[2] == 'M'; } + +void substring(char *string, char *string_start, int length) { + + strncpy(string, string_start, length); + string[length] = '\0'; +} + +char *getMonthName(int month) { + + switch(month) { + + case 1: return "Jan"; break; + case 2: return "Feb"; break; + case 3: return "Mar"; break; + case 4: return "Apr"; break; + case 5: return "May"; break; + case 6: return "Jun"; break; + case 7: return "Jul"; break; + case 8: return "Aug"; break; + case 9: return "Sep"; break; + case 10: return "Oct"; break; + case 11: return "Nov"; break; + case 12: return "Dec"; break; + + default: return "N/A"; break; + } +} + +int getMonthNumber(char* month) { + + if(!strcmp(month, "Jan")) return 1; + else if(!strcmp(month, "Feb")) return 2; + else if(!strcmp(month, "Mar")) return 3; + else if(!strcmp(month, "Apr")) return 4; + else if(!strcmp(month, "May")) return 5; + else if(!strcmp(month, "Jun")) return 6; + else if(!strcmp(month, "Jul")) return 7; + else if(!strcmp(month, "Aug")) return 8; + else if(!strcmp(month, "Sep")) return 9; + else if(!strcmp(month, "Oct")) return 10; + else if(!strcmp(month, "Nov")) return 11; + else if(!strcmp(month, "Dec")) return 12; +} + +// -------------------------------------------------------------------------------- // + +// Class game functions +void game_start(Game *game) { + + strcpy(game -> name, ""); + strcpy(game -> owners, ""); + strcpy(game -> website, ""); + strcpy(game -> developers, ""); + + for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) { + + strcpy(game -> languages[i], ""); + strcpy(game -> genres[i], ""); + } + + game -> release_date.month = -1; + game -> release_date.year = -1; + game -> app_id = -1; + game -> age = -1; + game -> dlcs = -1; + game -> avg_playtime = -1; + game -> price = -1; + game -> upvotes = -1; + game -> windows_os = false; + game -> mac_os = false; + game -> linux_os = false; + + game -> count_languages = 0; + game -> count_genres = 0; +} + +void game_print(Game *game) { + + int hours = game -> avg_playtime / 60, + minutes = game -> avg_playtime % 60; + + printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs); + + for(int i = 0; i < game -> count_languages; i++) { + + printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : ""); + } + + printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false"); + + if(isnan(game -> upvotes)) printf("0.0%% "); + else printf("%.0f%% ", game -> upvotes); + + if(hours > 0) + { + printf("%ih ", hours); + + if(minutes > 0) printf("%im ", minutes); + } + else { + + if(minutes > 0) printf("%im ", minutes); + else printf("null "); + } + + printf("%s [", game -> developers); + + for(int i = 0; i < game -> count_genres; i++) { + + printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : ""); + } + + printf("]\n"); +} + +Game game_clone(Game *game) { + + Game cloned; + + strcpy(cloned.name, game -> name); + strcpy(cloned.owners, game -> owners); + strcpy(cloned.website, game -> website); + strcpy(cloned.developers, game -> developers); + + for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]); + for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]); + + cloned.release_date.month = game -> release_date.month; + cloned.release_date.year = game -> release_date.year; + cloned.app_id = game -> app_id; + cloned.age = game -> age; + cloned.dlcs = game -> dlcs; + cloned.avg_playtime = game -> avg_playtime; + cloned.price = game -> price; + cloned.upvotes = game -> upvotes; + cloned.windows_os = game -> windows_os; + cloned.mac_os = game -> mac_os; + cloned.linux_os = game -> linux_os; + return cloned; +} + +void game_read(Game *game, char *line) { + + char c_search, sub[MAX_FIELD_SIZE]; + int index = 0, atr_index = 0; + + // ------------------------------------------------------------ // + + // Find "AppID" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> app_id = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Name" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> name, sub); + + if(c_search == ',') index++; + else if(c_search == '\"') index += 2; + + atr_index = index; + break; + } + } + } + else { + + strcpy(game -> name, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find release date + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + + char subDate[10]; + + substring(subDate, &sub[0], 3); + + game -> release_date.month = getMonthNumber(subDate); + + if(c_search == ',') { + + substring(subDate, &sub[4], 4); + + game -> release_date.year = atoi(subDate); + + index++; + } + else if(c_search == '\"') { + + int nmbSpace = 0; + + for(int i = 0; ; i++) { + + if(sub[i] == ' ') nmbSpace++; + + if(nmbSpace == 2) { + + i++; + + substring(subDate, &sub[i], 4); + + game -> release_date.year = atoi(subDate); + break; + } + } + + index += 2; + } + + atr_index = index; + break; + } + } + } + else { + + game -> release_date.month = 0; + game -> release_date.year = 0; + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Owners" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> owners, sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Age" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> age = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Price" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> price = atof(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "DLCs" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> dlcs = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Languages" + while(true) { + + index++; + + if(line[index] == ']') { + + index++; + + if(line[index] == ',') index++; + else if(line[index] == '\"') index += 2; + + atr_index = index; + break; + } + else if(line[index] == '\'') { + + int wordStart = index + 1; + + while(true) { + + index++; + + if(line[index] == '\'') { + + substring(sub, &line[wordStart], index - wordStart); + strcpy(game -> languages[game -> count_languages++], sub); + break; + } + } + } + } + + // ------------------------------------------------------------ // + + // Find "Website" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> website, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> website, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Windows" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> windows_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Mac" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> mac_os = true; + + atr_index = ++index; + break; + } + } + + // Find "Linux" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + if(!strcmp(sub, "True")) game -> linux_os = true; + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Upvotes" + int positives, negatives; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + positives = atoi(sub); + atr_index = ++index; + break; + } + } + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + negatives = atoi(sub); + atr_index = ++index; + break; + } + } + + game -> upvotes = (float)(positives * 100) / (float)(positives + negatives); + + // ------------------------------------------------------------ // + + // Find "AVG Playtime" + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + + game -> avg_playtime = atoi(sub); + + atr_index = ++index; + break; + } + } + + // ------------------------------------------------------------ // + + // Find "Developers" + if(line[atr_index] != ',') { + + if(line[atr_index] == '\"') { + + atr_index++; + c_search = '\"'; + } + else c_search = ','; + + while(true) { + + index++; + + if(line[index] == c_search) { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> developers, sub); + + atr_index = ++index; + break; + } + } + } + else { + + strcpy(game -> developers, "null"); + + atr_index = ++index; + } + + // ------------------------------------------------------------ // + + // Find "Genres" + if(index < strlen(line) - 1) { + + if(line[index] == ',') atr_index = ++index; + + if(line[atr_index] == '\"') { + + atr_index++; + + while(true) { + + index++; + + if(line[index] == ',') { + + substring(sub, &line[atr_index], index - atr_index); + strcpy(game -> genres[game -> count_genres++], sub); + + atr_index = ++index; + } + else if(line[index] == '\"') { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + if(sub[strlen(sub) - 1] == '\"') sub[strlen(sub) - 1] = '\0'; + else if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0'; + + strcpy(game -> genres[game -> count_genres++], sub); + break; + } + } + } + else { + + substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); + + strcpy(game -> genres[game -> count_genres++], sub); + } + } +} + +// -------------------------------------------------------------------------------- // + +// Functions - List +void list_insertBegin(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + for(int i = n; i > 0; i--) games[i] = games[i - 1]; + + games[0] = x; + n++; +} + +void list_insertEnd(Game x) { + + if(n >= MAX_GAMES) { + + printf("Insert error: MAX_GAMES reached"); + exit(1); + } + + games[n++] = x; +} + +void list_insert(Game x, int pos) { + + if(n >= MAX_GAMES || (pos < 0 || pos > n)) { + + printf("Insert error: %s", n >= MAX_GAMES ? "MAX_GAMES reached" : "Invalid position"); + exit(1); + } + + for(int i = n; i > pos; i--) games[i] = games[i-1]; + + games[pos] = x; + n++; +} + +Game list_removeBegin() { + + Game resp; + + if(n == 0) { + + printf("Remove error: Empty list"); + exit(1); + } + + resp = games[0]; + n--; + + for(int i = 0; i < n; i++) games[i] = games[i + 1]; + return resp; +} + +Game list_removeEnd() { + + if(n == 0) { + + printf("Remove error: Empty list"); + exit(1); + } + return games[--n]; +} + +Game list_remove(int pos) { + + Game resp; + + if(n >= MAX_GAMES || (pos < 0 || pos > n)) { + + printf("Insert error: %s!", n == 0 ? "Empty list" : "Invalid position"); + exit(1); + } + + resp = games[pos]; + n--; + + for(int i = pos; i < n; i++) games[i] = games[i+1]; + return resp; +} + +void list_print() { + + for(int i = 0; i < n; i++) { + + printf("[%i] ", i); + game_print(&games[i]); + } +} + +Game game_search(int app_id) { + + for(int i = 0; i < x; i++) { + + if(gamesFull[i].app_id == app_id) return gamesFull[i]; + } + + Game game; + game.app_id = -1; + return game; +} + +// ---------------------------------------------------------------------------------------------------------- // + +int main() { + + // ---------------------------------------------------------------------------------------- // + + // Fill full games list + FILE *fp; + char *line = NULL; + size_t len = 0; + size_t read; + + fp = fopen("/tmp/games.csv", "r"); + + if(fp == NULL) exit(EXIT_FAILURE); + + // -------------------------------------- // + + while((read = getline(&line, &len, fp)) != -1) { + + Game game; + + game_start(&game); + game_read(&game, line); + + gamesFull[x++] = game; + } + + fclose(fp); + + if(line) free(line); + + // ---------------------------------------------------------------------------------------- // + + char line_in[100]; + + // Fill production games list + scanf(" %[^\n]", line_in); + + while(true) { + + if(isFim(line_in)) break; + + // -------------------------- // + + int app_id = atoi(line_in); + + Game found = game_search(app_id); + + if(found.app_id != -1) list_insertEnd(found); + + // -------------------------- // + + scanf(" %[^\n]", line_in); + } + + // ---------------------------------------------------------------------------------------- // + + // Execute operations + int n_ops; + scanf("%i", &n_ops); + + for(int i = 0; i < n_ops; i++) { + + scanf(" %[^\n]", line_in); + + Game game; + char params[10]; + + if(line_in[0] == 'I') { + + substring(params, &line_in[3], strlen(line_in) - 3); + + if(line_in[1] == 'I') list_insertBegin(game_search(atoi(params))); + else if(line_in[1] == 'F') list_insertEnd(game_search(atoi(params))); + else if(line_in[1] == '*') { + + char appId[10], pos[10]; + int i = 0; + + while(true) { + + if(params[i] == ' ') { + + substring(pos, ¶ms[0], i); + substring(appId, ¶ms[i + 1], strlen(params) - i - 1); + break; + } + else i++; + } + + list_insert(game_search(atoi(appId)), atoi(pos)); + } + } + else if(line_in[0] == 'R') { + + if(line_in[1] == 'I') printf("(R) %s\n", list_removeBegin().name); + else if(line_in[1] == 'F') printf("(R) %s\n", list_removeEnd().name); + else if(line_in[1] == '*') { + + substring(params, &line_in[3], strlen(line_in) - 3); + + printf("(R) %s\n", list_remove(atoi(params)).name); + } + } + } + + list_print(); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.in b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.in new file mode 100644 index 0000000..90b8669 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.in @@ -0,0 +1,72 @@ +1189490 +300550 +49800 +1851280 +1112930 +275570 +1276550 +1096530 +690510 +1504570 +1369470 +270130 +336150 +573210 +886470 +1368820 +951530 +247370 +1879330 +1634290 +259570 +941650 +768450 +1347140 +722670 +711540 +450170 +730 +598550 +614090 +809440 +1923860 +559010 +1547380 +554310 +1124090 +292120 +691930 +325420 +663670 +503820 +49600 +49300 +1631930 +1038740 +336760 +64000 +487580 +410890 +363110 +FIM +20 +II 1487390 +II 258520 +II 1165270 +II 298140 +II 213610 +IF 50510 +IF 998660 +IF 1740720 +I* 10 24720 +I* 15 439550 +I* 20 1507410 +RF +RF +RF +RI +RI +R* 10 +RF +RF +RI \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.out b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.out new file mode 100644 index 0000000..e8bb1a6 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/pub.out @@ -0,0 +1,61 @@ +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Faefever +(R) NOBUNAGA'S AMBITION: Tendou with Power Up Kit +(R) Higurashi When They Cry Hou - Ch.2 Watanagashi +(R) Synthesis Universe -Episode 00- +[0] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] +[1] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified Chinese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[2] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[3] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[4] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[5] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[6] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[7] 24720 SPORE™ Galactic Adventures Jun/2009 500000 - 1000000 0 19.99 0 [English, French, German, Italian, Spanish - Spain, Dutch, Russian, Polish, Czech, Hungarian, Finnish, Norwegian, Swedish, Danish] http://www.spore.com/what/ga true false false 88% 15h 32m EA - Maxis [Action, Simulation] +[8] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[9] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[10] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[11] 439550 'n Verlore Verstand Apr/2016 50000 - 100000 0 14.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Swedish, Thai, Traditional Chinese, Turkish, Ukrainian] http://www.skobbejakgames.com true true true 39% 2h 20m Skobbejak Games,Skermunkel [Adventure, Casual, Indie] +[12] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[13] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[14] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[15] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[16] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] +[17] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[18] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[19] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[20] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[21] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[22] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[23] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[24] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[25] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[26] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[27] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[28] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[29] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[30] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[31] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[32] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[33] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[34] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[35] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[36] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[37] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[38] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[39] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[40] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[41] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[42] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[43] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[44] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[45] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[46] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[47] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[48] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[49] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[50] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[51] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/saida.out b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/saida.out new file mode 100644 index 0000000..6a85875 --- /dev/null +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/saida.out @@ -0,0 +1,61 @@ +(R) Have a Nice Death +(R) Sopwith VR +(R) Burn Zombie Burn! +(R) Sonic Adventure 2 +(R) Rhiannon: Curse of the Four Branches +(R) Faefever +(R) NOBUNAGA'S AMBITION: Tendou with Power Up Kit +(R) Higurashi When They Cry Hou - Ch.2 Watanagashi +(R) Synthesis Universe -Episode 00- +[0] 258520 The Vanishing of Ethan Carter Sep/2014 500000 - 1000000 0 19.99 2 [English, French, Italian, German, Spanish - Spain, Polish, Czech] http://EthanCarterGame.com true false false 89% 3h 13m The Astronauts [Adventure, Indie] +[1] 1487390 ANVIL Dec/2021 50000 - 100000 0 24.99 0 [English, Korean, German, Russian, Japanese, Simplified Chinese, Traditional Chinese, French, Polish, Portuguese - Brazil, Spanish - Latin America, Italian, Thai, Vietnamese] https://www.anvil.world/ true false false 63% 9h 51m Action Square [Action, Early Access] +[2] 1189490 觅长生 Nov/2019 500000 - 1000000 0 11.99 0 [Simplified Chinese] null true false false 91% 33h 39m Chalcedony Network [Indie, RPG, Strategy, Early Access] +[3] 300550 Shadowrun: Dragonfall - Director's Cut Sep/2014 500000 - 1000000 0 14.99 0 [English] http://harebrained-schemes.com/shadowrun/dragonfall/ true true true 89% 15h 1m Harebrained Schemes [Adventure, Indie, RPG, Strategy] +[4] 49800 Flight of the Icarus May/2010 50000 - 100000 0 4.99 0 [English] http://musegames.com/games/flight-of-the-icarus/ true true false 39% 15m Muse Games [Action, Indie] +[5] 1851280 Samurai Bringer Apr/2022 50000 - 100000 0 9.99 0 [English, Japanese, Simplified Chinese, Traditional Chinese] https://playism.com/game/samurai-bringer/ true false false 88% 5h 2m ALPHAWING Inc. [Action, Indie] +[6] 1112930 Dredgers Oct/2019 50000 - 100000 0 11.99 0 [English, Simplified Chinese] null true false false 92% null Pirate-Rob [Indie, RPG] +[7] 24720 SPORE™ Galactic Adventures Jun/2009 500000 - 1000000 0 19.99 0 [English, French, German, Italian, Spanish - Spain, Dutch, Russian, Polish, Czech, Hungarian, Finnish, Norwegian, Swedish, Danish] http://www.spore.com/what/ga true false false 88% 15h 32m EA - Maxis [Action, Simulation] +[8] 275570 Summoner Mar/2014 50000 - 100000 0 4.99 0 [English, German] null true false false 83% 3h 24m Volition [Action, RPG] +[9] 1096530 Solasta: Crown of the Magister May/2021 500000 - 1000000 0 15.99 4 [English, French, German, Simplified Chinese, Portuguese - Brazil, Russian] https://www.solasta-game.com/ true true false 89% 37h 56m Tactical Adventures [Adventure, RPG, Strategy] +[10] 690510 Immortal Soul: Black Survival Mar/2019 500000 - 1000000 0 0.00 0 [English, Japanese, Korean, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Traditional Chinese, Thai, Portuguese, Portuguese - Brazil] null true false false 79% 28h 5m Nimble Neuron [Free to Play, Indie, Strategy] +[11] 439550 'n Verlore Verstand Apr/2016 50000 - 100000 0 14.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Bulgarian, Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Swedish, Thai, Traditional Chinese, Turkish, Ukrainian] http://www.skobbejakgames.com true true true 39% 2h 20m Skobbejak Games,Skermunkel [Adventure, Casual, Indie] +[12] 1504570 Cultivation Tales Apr/2022 500000 - 1000000 0 19.99 0 [English, Simplified Chinese] null true false false 38% 27h 42m Ac Games [Action, Adventure, Indie, RPG, Strategy, Early Access] +[13] 1369470 Pincremental Aug/2020 50000 - 100000 0 0.00 0 [English] null true true false 80% null Makopaz [Casual, Free to Play, Indie, Simulation, Strategy] +[14] 270130 The Gallery - Episode 1: Call of the Starseed Apr/2016 50000 - 100000 0 14.99 1 [English] http://www.cloudheadgames.com true false false 84% 36m Cloudhead Games ltd. [Adventure, Casual, Indie] +[15] 336150 Virtual Pool 4 May/2015 50000 - 100000 0 24.99 0 [English] http://vponline.celeris.com true false false 83% null Celeris [Sports] +[16] 1507410 Coloring Book for Kids Mar/2021 50000 - 100000 0 0.00 1 [English, French, Italian, German, Arabic, Czech, Danish, Dutch, Hungarian, Japanese, Korean, Norwegian, Polish, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Latin America, Swedish, Thai, Turkish, Vietnamese] null true true false 89% null Peaksel [Casual, Free to Play, Indie] +[17] 573210 Mistwood Heroes Dec/2016 50000 - 100000 0 3.99 0 [English] null true false false 56% 4h Meepower [Action, Adventure, Casual, Indie, RPG] +[18] 886470 Another Otter Jul/2018 50000 - 100000 0 0.99 0 [English] null true false false 63% null PepoLab [Casual, Indie] +[19] 1368820 RollerCoaster Tycoon® 3: Complete Edition Sep/2020 50000 - 100000 0 7.99 0 [English, French, Italian, German, Spanish - Spain, Danish, Dutch, Finnish, Norwegian, Swedish] null true true false 83% 1h 15m Frontier Developments,Aspyr (Mac) [Simulation, Strategy] +[20] 951530 Alien Shooter - Last Hope Nov/2020 50000 - 100000 0 4.99 0 [English, Russian] http://www.sigma-team.net true false false 81% null Sigma Team Inc. [Action, Indie, RPG] +[21] 247370 Mutant Mudds Deluxe Nov/2013 50000 - 100000 0 9.99 0 [English] http://www.mutantmuddsdeluxe.com true false false 74% 3h 21m Renegade Kid [Action, Indie] +[22] 1879330 WARRIORS OROCHI 3 Ultimate Definitive Edition Jul/2022 50000 - 100000 0 39.99 0 [English, Simplified Chinese, Traditional Chinese, Japanese] https://www.gamecity.ne.jp/orochi2/ultimate/index.html true false false 88% null KOEI TECMO GAMES CO., LTD. [Action, Strategy] +[23] 1634290 Chuhou Joutai 2: Paraided! Jul/2021 50000 - 100000 0 4.99 0 [English, Japanese] https://drillimation.com/chuhou-joutai-2-paraided/ true false false 100% null Drillimation Systems [Action, Indie] +[24] 259570 EDEN STAR Jan/2015 50000 - 100000 0 19.99 0 [English] http://www.edenstargame.com true false false 61% 4h 31m Flix Interactive [Action, Adventure, Indie, Strategy, Early Access] +[25] 941650 The Island: Into The Mist Jan/2019 50000 - 100000 0 9.99 0 [Korean, English] https://imbada.itch.io/the-island true false false 69% 3h 14m SUPER WAVE Studio [Adventure, Indie] +[26] 768450 NUTS Feb/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Arabic, Dutch, Japanese, Korean, Portuguese - Brazil, Russian, Simplified Chinese, Traditional Chinese] http://nuts.game true true false 88% null Joon, Pol, Muutsch, Char & Torfi [Adventure, Simulation] +[27] 1347140 NEAR DEADline Aug/2020 50000 - 100000 0 0.00 1 [English] https://www.newgrounds.com/portal/view/736443 true true true 90% null Dumb ****ing Horse [Action, Casual, Free to Play, Indie] +[28] 722670 Chinese Chess/ Elephant Game: 象棋/ 中国象棋/ 中國象棋 Oct/2017 50000 - 100000 0 9.99 0 [Simplified Chinese, Traditional Chinese, English, Russian] null true false false 78% 1h 45m Wang Wenxi [Indie, Simulation, Strategy, Early Access] +[29] 711540 Lonely Mountains: Downhill Oct/2019 50000 - 100000 0 9.99 4 [English, French, Italian, German, Spanish - Spain, Russian, Simplified Chinese, Japanese, Korean, Portuguese - Brazil, Polish, Turkish] http://lonelymountains.com true true false 92% 1h 15m Megagon Industries [Action, Indie, Racing, Simulation, Sports] +[30] 450170 BOOR Feb/2017 50000 - 100000 0 0.99 0 [English, Spanish - Spain, French, German] http://www.dazlog.com/boor true true true 83% 4h 30m DazlogStudio [Adventure, Casual, Indie] +[31] 730 Counter-Strike: Global Offensive Aug/2012 50000000 - 100000000 0 0.00 1 [Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Portuguese - Brazil, Romanian, Russian, Simplified Chinese, Spanish - Spain, Swedish, Thai, Traditional Chinese, Turkish, Bulgarian, Ukrainian, Greek, Spanish - Latin America, Vietnamese] http://blog.counter-strike.net/ true true true 88% 508h 4m Valve,Hidden Path Entertainment [Action, Free to Play] +[32] 598550 HUNTDOWN May/2021 50000 - 100000 0 19.99 1 [English, French, Italian, German, Spanish - Spain, Japanese, Simplified Chinese] http://huntdown.com/ true true true 95% 11h 26m Easy Trigger Games [Action, Indie] +[33] 614090 Deadbeat Heroes Oct/2017 50000 - 100000 0 14.99 0 [English] https://www.upstreamarcade.com/deadbeat-heroes/ true false false 66% 4h 36m Deadbeat Productions [Action] +[34] 809440 Protolife Jun/2018 50000 - 100000 0 11.99 0 [English, Russian] null true true false 87% 15m Volcanic Giraffe [Indie, Strategy] +[35] 1923860 Neon Outlast Mar/2022 50000 - 100000 0 4.99 0 [English] null true false false 0% null Keep Spinning [Action, Indie] +[36] 559010 Cosmic Sugar VR Nov/2016 50000 - 100000 0 0.00 1 [English] http://cosmicsugarvr.com true false false 95% 5m David Lobser [Free to Play, Simulation] +[37] 1547380 KINGDOM of the DEAD Feb/2022 50000 - 100000 0 14.99 0 [English, French, Italian, German, Spanish - Spain, Simplified Chinese, Traditional Chinese, Korean, Japanese, Polish, Portuguese - Brazil, Russian] null true false false 83% null DIRIGO GAMES [Action, Adventure, Indie] +[38] 554310 Rage Wars Nov/2016 50000 - 100000 0 0.99 0 [English] http://www.lemondo.com/ true true true 89% 4h 24m Lemondo Games [Violent, Gore, Adventure, Casual, Indie] +[39] 1124090 告死天使之言-Death angel Aug/2019 50000 - 100000 0 0.99 1 [Simplified Chinese] https://space.bilibili.com/11591868/article true false false 81% null 我妻寒十 [Adventure, Indie] +[40] 292120 FINAL FANTASY® XIII Oct/2014 500000 - 1000000 13 15.99 0 [English, French, Italian, German, Spanish - Spain] http://www.square-enix.com/ true false false 74% 28h 58m Square Enix [RPG] +[41] 691930 MSI Electric City: Core Assault Sep/2017 50000 - 100000 0 0.00 0 [English] http://msi.com/to/e-city true false false 90% 32m HyperBot Studio [Action, Adventure, Casual, Free to Play, Indie] +[42] 325420 Homebrew - Patent Unknown Nov/2014 50000 - 100000 0 14.99 0 [English] http://www.homebrewgame.com true false false 76% 5h 48m Copybugpaste [Action, Indie, Racing, Simulation, Early Access] +[43] 663670 Killer Queen Black Oct/2019 50000 - 100000 0 9.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean] http://www.killerqueenblack.com true true false 93% 2h 11m Liquid Bit, LLC,BumbleBear Games, LLC [Action, Casual, Sports, Strategy] +[44] 503820 A Detective's Novel Jul/2016 500000 - 1000000 0 0.99 0 [English] http://amaterasusoftware.blogspot.hr/ true false false 68% 4h 24m Amaterasu Software [Adventure, Indie] +[45] 49600 Beat Hazard Apr/2010 500000 - 1000000 0 9.99 2 [English, French, German, Italian, Spanish - Spain, Dutch] http://www.coldbeamgames.com true true true 95% 7h 36m Cold Beam Games [Action, Casual, Indie] +[46] 49300 Commander: Conquest of the Americas Jul/2010 50000 - 100000 0 9.99 2 [English, French, German, Spanish - Spain] http://www.cota-game.com/ true false false 48% 11h 48m Nitro Games [Strategy] +[47] 1631930 The Insignia Project Jul/2021 50000 - 100000 0 1.99 0 [English] https://darkendstu.com/ true false false 75% null Dark End Studios [Indie, Early Access] +[48] 1038740 Fluffy Store Aug/2019 50000 - 100000 0 1.99 1 [English, Simplified Chinese, Traditional Chinese, Japanese] null true true false 97% 3h 9m AsicxArt [Adventure, Casual, Indie, RPG] +[49] 336760 Pilot Brothers Dec/2014 50000 - 100000 0 4.99 0 [English, French, Italian, German, Spanish - Spain, Japanese, Korean, Portuguese - Brazil, Russian, Traditional Chinese, Portuguese] null true false false 87% null 1C Wireless [Adventure, Casual] +[50] 64000 Men of War: Assault Squad Feb/2011 500000 - 1000000 0 9.99 5 [English, Russian, Italian, Spanish - Spain, French, German, Polish] http://www.menofwargame.com/assault/ true false false 88% 10h 5m Digitalmindsoft [Strategy] +[51] 487580 Ludo Supremo Jun/2016 50000 - 100000 0 1.99 0 [English] http://www.ensenasoft.com true false false 57% 3h 19m EnsenaSoft [Casual] From 6ffe2cb08e097ceeb4f6af8688a1de133672053c Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:13:49 -0300 Subject: [PATCH 09/13] Update - Versionamento --- .../tp02/TP02Q01 - Classe Filme em Java/Game.java | 12 ++++++++++++ .../tp02/TP02Q02 - Registro em C/Linux_Game.c | 10 ++++++++++ .../tp02/TP02Q02 - Registro em C/WSL_Game.c | 12 +++++++++++- .../TP02Q03 - Pesquisa sequencial em Java/Game.java | 12 ++++++++++++ .../TP02Q04 - Pesquisa binária em Java/Game.java | 12 ++++++++++++ .../TP02Q05 - Lista sequencial em Java/Game.java | 12 ++++++++++++ .../TP02Q06 - Pilha sequencial em Java/Game.java | 12 ++++++++++++ .../tp02/TP02Q07 - Fila circular em Java/Game.java | 12 ++++++++++++ .../{Game_Linux.c => Linux_Game.c} | 10 ++++++++++ .../tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c | 10 ++++++++++ 10 files changed, 113 insertions(+), 1 deletion(-) rename tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/{Game_Linux.c => Linux_Game.c} (99%) diff --git a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java index 55b765d..321ccc8 100644 --- a/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q01 - Classe Filme em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c index 575f5ac..14622e3 100644 --- a/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Linux_Game.c @@ -1,3 +1,13 @@ +/** + + * @file Linux_Game.c + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + // -------------------------------------------------------------------------------- // // Includes diff --git a/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c b/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c index 6bba16e..939563f 100644 --- a/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/WSL_Game.c @@ -1,3 +1,13 @@ +/** + + * @file WSL_Game.c + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + // -------------------------------------------------------------------------------- // // Includes @@ -662,7 +672,7 @@ int main() { FILE *fp; char *line = NULL; size_t len = 0; - ssize_t read; + size_t read; fp = fopen("/tmp/games.csv", "r"); diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java index cd344b0..cc42f1b 100644 --- a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java index 83fd29f..5912909 100644 --- a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java index 6810bd5..831e0ee 100644 --- a/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q05 - Lista sequencial em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java index 3228676..b098d6e 100644 --- a/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q06 - Pilha sequencial em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java index f98a763..120694b 100644 --- a/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java +++ b/tps/gabaritos/tp02/TP02Q07 - Fila circular em Java/Game.java @@ -1,3 +1,15 @@ +/** + + * @file Game.java + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + +// ----------------------------------------------------------------------------------------------------------------- // + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Linux_Game.c similarity index 99% rename from tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c rename to tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Linux_Game.c index 8554cb3..0a234d2 100644 --- a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Game_Linux.c +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/Linux_Game.c @@ -1,3 +1,13 @@ +/** + + * @file Linux_Game.c + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + // -------------------------------------------------------------------------------- // // Includes diff --git a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c index e85add2..f16988e 100644 --- a/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c +++ b/tps/gabaritos/tp02/TP02Q08 - Lista sequencial em C/WSL_Game.c @@ -1,3 +1,13 @@ +/** + + * @file WSL_Game.c + * @author Pedro Lopes + * @version 1.0 + * @date 2022-10-17 + * @copyright Copyright (c) 2022 + +**/ + // -------------------------------------------------------------------------------- // // Includes From 41746e8b266fb9f2996025971f81500179cd93e4 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:15:01 -0300 Subject: [PATCH 10/13] Small removes --- .../TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt | 1 - .../TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt delete mode 100644 tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt diff --git a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt b/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt deleted file mode 100644 index 4846eef..0000000 --- a/tps/gabaritos/tp02/TP02Q03 - Pesquisa sequencial em Java/753045_sequencial.txt +++ /dev/null @@ -1 +0,0 @@ -753045 24ms 1933 \ No newline at end of file diff --git a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt b/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt deleted file mode 100644 index f3866b4..0000000 --- a/tps/gabaritos/tp02/TP02Q04 - Pesquisa binária em Java/753045_sequencial.txt +++ /dev/null @@ -1 +0,0 @@ -753045 21ms 453 \ No newline at end of file From 68031cd1d654353783c01efa1fd0aa50409e9f53 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:16:00 -0300 Subject: [PATCH 11/13] =?UTF-8?q?Organiza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tps/fonte/Game.c | 728 --------- tps/fonte/Game.java | 577 ------- .../tp02/TP02Q02 - Registro em C/Game_alt.c} | 1442 ++++++++--------- 3 files changed, 721 insertions(+), 2026 deletions(-) delete mode 100644 tps/fonte/Game.c delete mode 100644 tps/fonte/Game.java rename tps/{fonte/game01.c => gabaritos/tp02/TP02Q02 - Registro em C/Game_alt.c} (96%) diff --git a/tps/fonte/Game.c b/tps/fonte/Game.c deleted file mode 100644 index 4abec4d..0000000 --- a/tps/fonte/Game.c +++ /dev/null @@ -1,728 +0,0 @@ -/** - - * @file Game.c - * @author Pedro Lopes - * @version 0.2 - * @date 2022-10-02 - * @copyright Copyright (c) 2022 - -**/ - -// -------------------------------------------------------------------------------- // - -// Includes -#include -#include -#include -#include -#include - -// -------------------------------------------------------------------------------- // - -// Definitions -#define MAX_GAMES 9000 -#define MAX_FIELD_SIZE 250 -#define MAX_STRING_ARRAY_SIZE 100 - -// -------------------------------------------------------------------------------- // - -// Structs -typedef struct { - - int year, - month; -} Date; - -typedef struct { - - char name[MAX_FIELD_SIZE], - owners[MAX_FIELD_SIZE], - website[MAX_FIELD_SIZE], - developers[MAX_FIELD_SIZE], - languages[MAX_STRING_ARRAY_SIZE][30], - genres[MAX_STRING_ARRAY_SIZE][30]; - - Date release_date; - int app_id, age, dlcs, avg_playtime, count_languages, count_genres; - float price, upvotes; - bool windows_os, mac_os, linux_os; - -} Game; - -// -------------------------------------------------------------------------------- // - -// Global variables -Game games[MAX_GAMES]; -int n = 0; - -// -------------------------------------------------------------------------------- // - -// Functions -bool isFim(char* line) { return line[0] == 'F' && line[1] == 'I' && line[2] == 'M'; } - -void substring(char *string, char *string_start, int length) { - - strncpy(string, string_start, length); - string[length] = '\0'; -} - -char *getMonthName(int month) { - - switch(month) { - - case 1: return "Jan"; break; - case 2: return "Feb"; break; - case 3: return "Mar"; break; - case 4: return "Apr"; break; - case 5: return "May"; break; - case 6: return "Jun"; break; - case 7: return "Jul"; break; - case 8: return "Aug"; break; - case 9: return "Sep"; break; - case 10: return "Oct"; break; - case 11: return "Nov"; break; - case 12: return "Dec"; break; - - default: return "N/A"; break; - } -} - -int getMonthNumber(char* month) { - - if(!strcmp(month, "Jan")) return 1; - else if(!strcmp(month, "Feb")) return 2; - else if(!strcmp(month, "Mar")) return 3; - else if(!strcmp(month, "Apr")) return 4; - else if(!strcmp(month, "May")) return 5; - else if(!strcmp(month, "Jun")) return 6; - else if(!strcmp(month, "Jul")) return 7; - else if(!strcmp(month, "Aug")) return 8; - else if(!strcmp(month, "Sep")) return 9; - else if(!strcmp(month, "Oct")) return 10; - else if(!strcmp(month, "Nov")) return 11; - else if(!strcmp(month, "Dec")) return 12; -} - -// -------------------------------------------------------------------------------- // - -// Class game functions -void game_start(Game *game) { - - strcpy(game -> name, ""); - strcpy(game -> owners, ""); - strcpy(game -> website, ""); - strcpy(game -> developers, ""); - - for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) { - - strcpy(game -> languages[i], ""); - strcpy(game -> genres[i], ""); - } - - game -> release_date.month = -1; - game -> release_date.year = -1; - game -> app_id = -1; - game -> age = -1; - game -> dlcs = -1; - game -> avg_playtime = -1; - game -> price = -1; - game -> upvotes = -1; - game -> windows_os = false; - game -> mac_os = false; - game -> linux_os = false; - - game -> count_languages = 0; - game -> count_genres = 0; -} - -void game_print(Game *game) { - - int hours = game -> avg_playtime / 60, - minutes = game -> avg_playtime % 60; - - printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs); - - for(int i = 0; i < game -> count_languages; i++) { - - printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : ""); - } - - printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false"); - - if(isnan(game -> upvotes)) printf("0.0%% "); - else printf("%.0f%% ", game -> upvotes); - - if(hours > 0) - { - printf("%ih ", hours); - - if(minutes > 0) printf("%im ", minutes); - } - else { - - if(minutes > 0) printf("%im ", minutes); - else printf("null "); - } - - printf("%s [", game -> developers); - - for(int i = 0; i < game -> count_genres; i++) { - - printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : ""); - } - - printf("]\n"); -} - -Game game_clone(Game *game) { - - Game cloned; - - strcpy(cloned.name, game -> name); - strcpy(cloned.owners, game -> owners); - strcpy(cloned.website, game -> website); - strcpy(cloned.developers, game -> developers); - - for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]); - for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]); - - cloned.release_date.month = game -> release_date.month; - cloned.release_date.year = game -> release_date.year; - cloned.app_id = game -> app_id; - cloned.age = game -> age; - cloned.dlcs = game -> dlcs; - cloned.avg_playtime = game -> avg_playtime; - cloned.price = game -> price; - cloned.upvotes = game -> upvotes; - cloned.windows_os = game -> windows_os; - cloned.mac_os = game -> mac_os; - cloned.linux_os = game -> linux_os; - return cloned; -} - -void game_read(Game *game, char *line) { - - char c_search, sub[MAX_FIELD_SIZE]; - int index = 0, atr_index = 0; - - // ------------------------------------------------------------ // - - // Find "AppID" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - game -> app_id = atoi(sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Name" - if(line[atr_index] != ',') { - - if(line[atr_index] == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line[index] == c_search) { - - substring(sub, &line[atr_index], index - atr_index); - strcpy(game -> name, sub); - - if(c_search == ',') index++; - else if(c_search == '\"') index += 2; - - atr_index = index; - break; - } - } - } - else { - - strcpy(game -> name, "null"); - - atr_index = ++index; - } - - // ------------------------------------------------------------ // - - // Find release date - if(line[atr_index] != ',') { - - if(line[atr_index] == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line[index] == c_search) { - - substring(sub, &line[atr_index], index - atr_index); - - char subDate[10]; - - substring(subDate, &sub[0], 3); - - game -> release_date.month = getMonthNumber(subDate); - - if(c_search == ',') { - - substring(subDate, &sub[4], 4); - - game -> release_date.year = atoi(subDate); - - index++; - } - else if(c_search == '\"') { - - int nmbSpace = 0; - - for(int i = 0; ; i++) { - - if(sub[i] == ' ') nmbSpace++; - - if(nmbSpace == 2) { - - i++; - - substring(subDate, &sub[i], 4); - - game -> release_date.year = atoi(subDate); - break; - } - } - - index += 2; - } - - atr_index = index; - break; - } - } - } - else { - - game -> release_date.month = 0; - game -> release_date.year = 0; - - atr_index = ++index; - } - - // ------------------------------------------------------------ // - - // Find "Owners" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - strcpy(game -> owners, sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Age" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - game -> age = atoi(sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Price" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - game -> price = atof(sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "DLCs" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - game -> dlcs = atoi(sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Languages" - while(true) { - - index++; - - if(line[index] == ']') { - - index++; - - if(line[index] == ',') index++; - else if(line[index] == '\"') index += 2; - - atr_index = index; - break; - } - else if(line[index] == '\'') { - - int wordStart = index + 1; - - while(true) { - - index++; - - if(line[index] == '\'') { - - substring(sub, &line[wordStart], index - wordStart); - strcpy(game -> languages[game -> count_languages++], sub); - break; - } - } - } - } - - // ------------------------------------------------------------ // - - // Find "Website" - if(line[atr_index] != ',') { - - if(line[atr_index] == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line[index] == c_search) { - - substring(sub, &line[atr_index], index - atr_index); - strcpy(game -> website, sub); - - atr_index = ++index; - break; - } - } - } - else { - - strcpy(game -> website, "null"); - - atr_index = ++index; - } - - // ------------------------------------------------------------ // - - // Find "Windows" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - if(!strcmp(sub, "True")) game -> windows_os = true; - - atr_index = ++index; - break; - } - } - - // Find "Mac" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - if(!strcmp(sub, "True")) game -> mac_os = true; - - atr_index = ++index; - break; - } - } - - // Find "Linux" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - if(!strcmp(sub, "True")) game -> linux_os = true; - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Upvotes" - int positives, negatives; - - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - positives = atoi(sub); - atr_index = ++index; - break; - } - } - - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - negatives = atoi(sub); - atr_index = ++index; - break; - } - } - - game -> upvotes = (float)(positives * 100) / (float)(positives + negatives); - - // ------------------------------------------------------------ // - - // Find "AVG Playtime" - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - - game -> avg_playtime = atoi(sub); - - atr_index = ++index; - break; - } - } - - // ------------------------------------------------------------ // - - // Find "Developers" - if(line[atr_index] != ',') { - - if(line[atr_index] == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line[index] == c_search) { - - substring(sub, &line[atr_index], index - atr_index); - strcpy(game -> developers, sub); - - atr_index = ++index; - break; - } - } - } - else { - - strcpy(game -> developers, "null"); - - atr_index = ++index; - } - - // ------------------------------------------------------------ // - - // Find "Genres" - if(index < strlen(line) - 1) { - - if(line[index] == ',') atr_index = ++index; - - if(line[atr_index] == '\"') { - - atr_index++; - - while(true) { - - index++; - - if(line[index] == ',') { - - substring(sub, &line[atr_index], index - atr_index); - strcpy(game -> genres[game -> count_genres++], sub); - - atr_index = ++index; - } - else if(line[index] == '\"') { - - substring(sub, &line[atr_index], strlen(line) - 1 - atr_index); - - if(sub[strlen(sub) - 1] == '\"') sub[strlen(sub) - 1] = '\0'; - else if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0'; - - strcpy(game -> genres[game -> count_genres++], sub); - break; - } - } - } - else { - - substring(sub, &line[atr_index], strlen(line) - 2 - atr_index); - - strcpy(game -> genres[game -> count_genres++], sub); - } - } -} - -// -------------------------------------------------------------------------------- // - -// Functions - List -void list_insert(Game x) { - - if(n >= MAX_GAMES) { - - printf("Insert error: MAX_GAMES reached"); - exit(1); - } - - games[n++] = x; -} - -// ---------------------------------------------------------------------------------------------------------- // - -int main() { - - // ------------------------------------------------------------ // - - // First part - Read all games - - // Open CSV file - FILE *fp; - char *line = NULL; - size_t len = 0; - size_t read; - - fp = fopen("/tmp/games.csv", "r"); - - if(fp == NULL) exit(EXIT_FAILURE); - - // ------------------------- // - - // Fill games list - while((read = getline(&line, &len, fp)) != -1) { - - Game game; - - game_start(&game); - game_read(&game, line); - list_insert(game); - } - - // ------------------------- // - - fclose(fp); - - if(line) free(line); - - // ------------------------------------------------------------ // - - // Second part - Print .in games - - char in[15]; - scanf(" %[^\n]s", in); - - while(true) { - - if(isFim(in)) break; - else { - - int app_id = atoi(in); - - for(int i = 0; i < n; i++) { - - if(games[i].app_id == app_id) { - - game_print(&games[i]); - break; - } - } - - // ------------------------- // - - scanf(" %[^\n]s", in); - } - } - return EXIT_SUCCESS; -} \ No newline at end of file diff --git a/tps/fonte/Game.java b/tps/fonte/Game.java deleted file mode 100644 index be149f5..0000000 --- a/tps/fonte/Game.java +++ /dev/null @@ -1,577 +0,0 @@ -/** - - * @file Game.java - * @author Pedro Lopes - * @version 0.2 - * @date 2022-10-02 - * @copyright Copyright (c) 2022 - -**/ - -// ----------------------------------------------------------------------------------------------------------------- // - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Locale; -import java.util.Scanner; - -// ----------------------------------------------------------------------------------------------------------------- // - -class Game { - - static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH); - - private String name, owners, website, developers; - private ArrayList languages, genres; - private Date release_date; - private int app_id, age, dlcs, avg_playtime; - private float price, upvotes; - private boolean windows, mac, linux; - - public Game() { - - this.name = this.owners = this.website = this.developers = null; - this.languages = new ArrayList(); - this.genres = new ArrayList(); - this.release_date = null; - this.app_id = this.age = this.dlcs = this.avg_playtime = -1; - this.price = this.upvotes = -1; - this.windows = this.mac = this.linux = false; - } - - public Game(String name, String owners, String website, String developers, ArrayList languages, ArrayList genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) { - - this.name = name; - this.owners = owners; - this.website = website; - this.developers = developers; - this.languages = languages; - this.genres = genres; - this.release_date = release_date; - this.app_id = app_id; - this.age = age; - this.dlcs = dlcs; - this.upvotes = upvotes; - this.avg_playtime = avg_playtime; - this.price = price; - this.windows = windows; - this.mac = mac; - this.linux = linux; - } - - public void setName(String name) { this.name = name; } - public void setOwners(String owners) { this.owners = owners; } - public void setWebsite(String website) { this.website = website; } - public void setDevelopers(String developers) { this.developers = developers; } - public void setLanguages(ArrayList languages) { this.languages = languages; } - public void setGenres(ArrayList genres) { this.genres = genres; } - public void setReleaseDate(Date release_date) { this.release_date = release_date; } - public void setAppId(int app_id) { this.app_id = app_id; } - public void setAge(int age) { this.age = age; } - public void setDlcs(int dlcs) { this.dlcs = dlcs; } - public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; } - public void setPrice(float price) { this.price = price; } - public void setUpvotes(float upvotes) { this.upvotes = upvotes; } - public void setWindows(boolean windows) { this.windows = windows; } - public void setMac(boolean mac) { this.mac = mac; } - public void setLinux(boolean linux) { this.linux = linux; } - - public String getName() { return this.name; } - public String getOwners() { return this.owners; } - public String getWebsite() { return this.website; } - public String getDevelopers() { return this.developers; } - public ArrayList getLanguages() { return this.languages; } - public ArrayList getGenres() { return this.genres; } - public Date getReleaseDate() { return this.release_date; } - public int getAppId() { return this.app_id; } - public int getAge() { return this.age; } - public int getDlcs() { return this.dlcs; } - public int getAvgPlaytime() { return this.avg_playtime; } - public float getPrice() { return this.price; } - public float getUpvotes() { return this.upvotes; } - public boolean getWindows() { return this.windows; } - public boolean getMac() { return this.mac; } - public boolean getLinux() { return this.linux; } - - public Game clone() { - - Game cloned = new Game(); - - cloned.name = this.name; - cloned.owners = this.owners; - cloned.website = this.website; - cloned.developers = this.developers; - cloned.languages = this.languages; - cloned.genres = this.genres; - cloned.release_date = this.release_date; - cloned.app_id = this.app_id; - cloned.age = this.age; - cloned.dlcs = this.dlcs; - cloned.avg_playtime = this.avg_playtime; - cloned.price = this.price; - cloned.upvotes = this.upvotes; - cloned.windows = this.windows; - cloned.mac = this.mac; - cloned.linux = this.linux; - - return cloned; - } - - public void read(String line) { - - char c_search; - int index = 0, atr_index = 0; - - // ---------------------------------- // - - // Find "AppID" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.app_id = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Name" - if(line.charAt(atr_index) != ',') { - - if(line.charAt(atr_index) == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line.charAt(index) == c_search) { - - this.name = line.substring(atr_index, index); - - if(c_search == ',') index++; - else if(c_search == '\"') index += 2; - - atr_index = index; - break; - } - } - } - else atr_index = ++index; - - // ---------------------------------- // - - // Find release date - if(line.charAt(atr_index) != ',') { - - SimpleDateFormat df; - - if(line.charAt(atr_index) == '\"') { - - df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); - - atr_index++; - c_search = '\"'; - } - else { - - df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH); - - c_search = ','; - } - - while(true) { - - index++; - - if(line.charAt(index) == c_search) { - - try { this.release_date = df.parse(line.substring(atr_index, index)); } - catch (java.text.ParseException e) { e.printStackTrace(); } - - if(c_search == ',') index++; - else if(c_search == '\"') index += 2; - - atr_index = index; - break; - } - } - } - else atr_index = ++index; - - // ---------------------------------- // - - // Find "Owners" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.owners = line.substring(atr_index, index); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Age" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.age = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Price" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.price = Float.parseFloat(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "DLCs" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.dlcs = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Languages" - while(true) { - - index++; - - if(line.charAt(index) == ']') { - - index++; - - if(line.charAt(index) == ',') index++; - else if(line.charAt(index) == '\"') index += 2; - - atr_index = index; - break; - } - else if(line.charAt(index) == '\'') { - - int wordStart = index + 1; - - while(true) { - - index++; - - if(line.charAt(index) == '\'') { - - this.languages.add(line.substring(wordStart, index)); - break; - } - } - } - } - - // ---------------------------------- // - - // Find "Website" - if(line.charAt(atr_index) != ',') { - - if(line.charAt(atr_index) == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line.charAt(index) == c_search) { - - this.website = line.substring(atr_index, index); - - atr_index = ++index; - break; - } - } - } - else atr_index = ++index; - - // ---------------------------------- // - - // Find "Windows" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.windows = Boolean.parseBoolean(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // Find "Mac" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.mac = Boolean.parseBoolean(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // Find "Linux" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.linux = Boolean.parseBoolean(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Upvotes" - int positives, negatives; - - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - positives = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - negatives = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - this.upvotes = (float)(positives * 100) / (float)(positives + negatives); - - // ---------------------------------- // - - // Find "AVG Playtime" - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.avg_playtime = Integer.parseInt(line.substring(atr_index, index)); - - atr_index = ++index; - break; - } - } - - // ---------------------------------- // - - // Find "Developers" - if(line.charAt(atr_index) != ',') { - - if(line.charAt(atr_index) == '\"') { - - atr_index++; - c_search = '\"'; - } - else c_search = ','; - - while(true) { - - index++; - - if(line.charAt(index) == c_search) { - - this.developers = line.substring(atr_index, index); - - atr_index = ++index; - break; - } - } - } - else atr_index = ++index; - - // ---------------------------------- // - - // Find "Genres" - if(index < line.length() - 1) { - - if(line.charAt(index) == ',') atr_index = ++index; - if(line.charAt(atr_index) == '\"') { - - atr_index++; - - while(true) { - - index++; - - if(line.charAt(index) == ',') { - - this.genres.add(line.substring(atr_index, index)); - - atr_index = ++index; - } - else if(line.charAt(index) == '\"') { - - this.genres.add(line.substring(atr_index, line.length() - 1)); - break; - } - } - } - else this.genres.add(line.substring(atr_index, line.length())); - } - - // -------------------------------------------------------------------------------- // - } - - public void print() { - - String avg_pt = null; - - if(this.avg_playtime == 0) avg_pt = "null "; - else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m "; - else { - - if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h "; - else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m "; - } - - DecimalFormat df = new DecimalFormat("##"); - - System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres); - } - - // -------------------------------------------------------------------------------------- // - - public static boolean isFim(String line) { return line.compareTo("FIM") == 0; } - - // -------------------------------------------------------------------------------------- // - - public static void main(String[] args) throws Exception { - - ArrayList games = new ArrayList(); - - // ------------------------------------------------------------------------------ // - - try { - - // Read CSV file - String basefile = "/tmp/games.csv"; - - FileInputStream fstream = new FileInputStream(basefile); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - - // ------------------------------------ // - - // Explode CSV file reading games - String line; - - while((line = br.readLine()) != null) { - - Game game = new Game(); - - game.read(line); - games.add(game); - } - - // Close CSV file - fstream.close(); - } - catch(IOException e) { e.printStackTrace(); } - - // ---------------------------------------------------------------------------------------------- // - - // Read .in file - Scanner scr = new Scanner(System.in); - String line = scr.nextLine(); - - while(true) { - - if(isFim(line)) break; - - int app_id = Integer.parseInt(line); - - // Search game with .in id - for(Game game : games) { - - if(game.getAppId() == app_id) game.print(); - } - - line = scr.nextLine(); - } - - // ---------------------------------------------------------------------------------------------- // - - scr.close(); - } - - // ---------------------------------------------------------------------------------------------- // -} \ No newline at end of file diff --git a/tps/fonte/game01.c b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Game_alt.c similarity index 96% rename from tps/fonte/game01.c rename to tps/gabaritos/tp02/TP02Q02 - Registro em C/Game_alt.c index 39becc0..5c96434 100644 --- a/tps/fonte/game01.c +++ b/tps/gabaritos/tp02/TP02Q02 - Registro em C/Game_alt.c @@ -1,721 +1,721 @@ -// ------------------------------------------------------------------------------ // -// Author: Vinicius Gabriel dos Santos - https://github.com/ravixr -// Sep/2022 -// -// DESCRIPTION: -// In addition to the game data structure and -// the solution to the second question of the assignment, -// this file contains a basic implementation of a string type -// which was extensively used in the game data structure -// as well as in the solution algorithm. -// ------------------------------------------------------------------------------ // - -#include -#include -#include -#include -#include -#include - -#define GAME_FIELDS_SIZE 17 -#define MAX_FIELD_SIZE 500 -#define MAX_LINE_SIZE 1000 -#define MAX_GAMES 100 - -// If on windows remove first slash -> 'tmp/games.csv' -#define FILE_PATH "/tmp/games.csv" - -// Assert macro to print custom message when assertion fails -#define assert__(x) for (; !(x); assert(x)) - -// --------------------------- my_very_basic_string.h --------------------------- // - -typedef struct string_t string; - -typedef struct strarr_t strarr; - -struct string_t { - char *buf; - char (*char_at)(const string *, size_t); - int (*compare)(const string *, const string *); - void (*delete)(string *); - size_t (*find)(const string *, const char *); - size_t (*length)(const string *); - void (*replace)(string *, const char *, const char *); - strarr (*split)(const string *, const char *); - string (*substr)(const string *, size_t, size_t); - float (*to_float)(const string *); - int (*to_int)(const string *); - void (*trim)(string *); -}; - -struct strarr_t { - string *src; - size_t length; - void (*delete)(strarr *); -}; - -// string functions declaration -char str_char_at(const string *, size_t); -int str_compare(const string *, const string *); -void str_delete(string *); -size_t str_find(const string *, const char *); -size_t str_length(const string *); -void str_replace(string *, const char*, const char *); -string new_string(char *); -strarr str_split(const string *, const char *); -string str_substr(const string *, size_t, size_t); -float str_to_float(const string *); -int str_to_int(const string *); -void str_trim(string *); - -// strarr functions declaration -strarr new_strarr(string *, size_t); -void strarr_delete(strarr *); - -// --------------------------- my_very_basic_string.c --------------------------- // - -// Fuction to initialize string type -string new_string(char *src) -{ - string str; - if (src != NULL) { - if (strcmp(src, "") != 0) { - str.buf = malloc(sizeof(char) * (strlen(src) + 1)); - strcpy(str.buf, src); - } else { - str.buf = malloc(sizeof(char) * 5); - strcpy(str.buf, "null"); - } - } else str.buf = NULL; - str.char_at = &str_char_at; - str.compare = &str_compare; - str.delete = &str_delete; - str.find = &str_find; - str.replace = &str_replace; - str.length = &str_length; - str.split = &str_split; - str.substr = &str_substr; - str.to_float = &str_to_float; - str.to_int = &str_to_int; - str.trim = &str_trim; - return str; -} - -// Fuction to deallocate string type -void str_delete(string *self) -{ - free(self->buf); -} - -// Returns character present in the specified index of the string -// e.g: "foo" idx: 0 -> 'f' -char str_char_at(const string *self, size_t idx) -{ - // Macro to assert index is in bounds - assert__(idx < strlen(self->buf)) { - fprintf(stderr, "String index %ld is out of bounds\n", idx); - } - return self->buf[idx]; -} - -// Allows comparison between string type variables using strcmp in the raw data -int str_compare(const string *self, const string *another_str) -{ - return strcmp(self->buf, another_str->buf); -} - -// Searches the string for the first occurrence of the pattern specified. -// Returns the index position of the first character of the pattern -// or the length of the string if the pattern is not found -// e.g.: "foo bar", "bar" -> 4 | "foo bar", "baz" -> 7 -size_t str_find(const string *self, const char *lkf) -{ - size_t i = 0, - self_len = strlen(self->buf), - lkf_len = strlen(lkf); - - // Macro to assert pattern string is valid - assert__((strcmp(lkf, "") != 0) && (lkf_len <= self_len)) { - fprintf(stderr, "Pattern '%s' is invalid for the specified string\n", lkf); - } - - // Find algorithm - for (size_t j = 0; i < self_len; i++) { - if (self->buf[i] == lkf[j]) { - j++; - } else { - i-= j; j = 0; - } - if (j == lkf_len) { - i -= (j - 1); - break; - } - } - return i; -} - -// Returns the length of the string using strlen in the raw data -size_t str_length(const string *self) -{ - return strlen(self->buf); -} - -// Replaces all occurrences of specified pattern in the string with the new specified pattern -// if the string doesn't contains the pattern to be replaced the string is not changed -// e.g.: "foobar", "bar", "" -> "foo" | "foobar", "baz", "" -> "foobar" -void str_replace(string *self, const char *old_val, const char *new_val) -{ - // Saving useful lengths in variables - size_t old_len = strlen(self->buf), - nv_len = strlen(new_val), - ov_len = strlen(old_val); - - // Macro to assert given pattern is valid - assert__((strcmp(old_val, "") != 0) && (old_len >= ov_len)) { - fprintf(stderr, "Invalid pattern for argument 'old_val'\n"); - } - - // Calculating the max possible amount of patterns in the string - // then allocating an array to store their indexes - size_t idx_sz = (old_len / ov_len), - *idx = malloc(sizeof(size_t) * (idx_sz + 1)), - idx_i = 0, last_idx = 0, skip = 0; - - // Getting all starting indexes of where the pattern is found - string aux = new_string(NULL); - aux.buf = (self->buf); - while ((idx_i <= idx_sz) && (last_idx < old_len)) { - idx[idx_i] = str_find(&aux, old_val) + skip; - skip = idx[idx_i++] + ov_len; - aux.buf = (self->buf + skip); - last_idx = idx[idx_i - 1]; - } - - // Checking if the pattern is actually on the string - if (idx[0] != old_len) { - // Assuring 'idx_i' will not be 0 - idx_i > 1 ? (idx_i -= 1) : (idx_i = 1); - - // Calculating new length of the string then allocating - size_t new_len = (old_len + ((nv_len - ov_len) * idx_i)); - char *tmp = malloc(sizeof(char) * (new_len + 1)); - - // Main Replacement algorithm: copies old string char by char, - // when the index is equal to the range of the next found pattern - // starts copying the new pattern char by chat into the string - if (nv_len == 0) nv_len = 1; - for (size_t i = 0, j = 0, k = 0, l = 0; i < new_len;) { - if (k >= idx[l] && k < (idx[l] + ov_len)) { - if (strcmp(new_val, "") != 0) - tmp[i++] = new_val[j]; - j++; - if (j == nv_len) { - k += ov_len; - j = 0; l++; - } - } else tmp[i++] = self->buf[k++]; - } - tmp[new_len] = '\0'; // Adding null terminator in the new string - free(self->buf); // freeing old string - self->buf = tmp; // Pointing to new string - } - free(idx); // freeing array of indexes of the old string -} - -// Uses strtok to split the raw char array -// then build new strings with the splitted char arrays -// and bundle all of them in the strarr type -// e.g.: 'foo,bar' ',' -> ['foo', 'bar'] -strarr str_split(const string *self, const char *delim) -{ - char *str = malloc(sizeof(char) * (strlen(self->buf) + 1)); - strcpy(str, self->buf); - char *token = strtok(str, delim); - size_t count = 0; - strarr str_arr = new_strarr(NULL, 0); - string *tmp; - while(token != NULL) { - tmp = realloc(str_arr.src, sizeof(string) * (count + 1)); - if (tmp != NULL) { - tmp[count++] = new_string(token); - str_arr.src = tmp; - } - token = strtok(NULL, delim); - } - free(str); - free(token); - str_arr.length = count; - return str_arr; -} - -// Returns a new string that is a copy of the portion of the original string -// that starts at character position 'pos' and spans 'len' characters -// e.g.: "foo bar" pos: 4, len: 3 -> "bar" -string str_substr(const string *self, size_t pos, size_t len) -{ - // Macro to assert pos and len are in bounds - assert__((pos + len) <= strlen(self->buf)) { - fprintf(stderr, "String index %ld is out of bounds for '%s'\n", (pos + len), self->buf); - } - string substr = new_string(NULL); - substr.buf = malloc(sizeof(char) * (len + 1)); - for (size_t i = 0, j = 0; i < len; i++, j++) { - substr.buf[j] = self->buf[pos + i]; - } - substr.buf[len] = '\0'; - return substr; -} - -// Uses atof to convert string to float -float str_to_float(const string *self) -{ - return atof(self->buf); -} - -// Uses atoi to convert string to int -int str_to_int(const string *self) -{ - return atoi(self->buf); -} - -// Removes all spaces only from the beginning and ending of the string -// e.g.: " foo " -> "foo" | "foo bar" -> "foo bar" -void str_trim(string *self) -{ - size_t i = 0, j = (strlen(self->buf) - 1); - while (self->buf[i] == ' ' || self->buf[j] == ' ') { - if (self->buf[i] == ' ') i++; - if (self->buf[j] == ' ') j--; - } - string tmp = self->substr(self, i, (j - i) + 1); - free(self->buf); - self->buf = tmp.buf; -} - -// Fuction to initialize string array type -strarr new_strarr(string *src, size_t src_length) -{ - strarr str_arr; - if (src != NULL) - str_arr.src = src; - else { - src_length = (src_length > 0 ? src_length : 1); - str_arr.src = malloc(sizeof(string *)); - } - str_arr.length = src_length; - str_arr.delete = &strarr_delete; - return str_arr; -} - -// Fuction to deallocate string array type -void strarr_delete(strarr *self) -{ - for (size_t i = 0; i < self->length; i++) { - free(self->src[i].buf); - } - free(self->src); -} - -// ----------------------------------- game.h ----------------------------------- // - -typedef struct date_t date; - -struct date_t { - uint8_t day; - char month[4]; - unsigned year; - size_t value; -}; - -date new_date(string *); -unsigned strmon_to_int(const char *); - -typedef struct game_t game; - -struct game_t { - unsigned app_id; - string name; - date release_date; - string owners; - unsigned age; - float price; - unsigned dlcs; - strarr languages; - string website; - bool windows; - bool mac; - bool linux_; - float upvotes; - unsigned avg_pt; - string developers; - strarr genres; -}; - -game empty_game(void); -game new_game(string *); -game str_to_game(string *); -game chararr_to_game(char *); -void game_print(game *); -void game_read_csv(game *, size_t *, size_t); -char *avgpt_to_chararr (unsigned); - -// ----------------------------------- game.c ----------------------------------- // - -// Converts month abbreviated char array in format 'Mmm' -// to unsigned int, if unsuccessful returns 0 -// e.g.: "Aug" -> 8 | "aug" -> 0 -unsigned strmon_to_int(const char *mon) -{ - unsigned i = 0; - if (strcmp(mon, "Jan") == 0) { i = 1; } - else if (strcmp(mon, "Feb") == 0) { i = 2; } - else if (strcmp(mon, "Mar") == 0) { i = 3; } - else if (strcmp(mon, "Apr") == 0) { i = 4; } - else if (strcmp(mon, "May") == 0) { i = 5; } - else if (strcmp(mon, "Jun") == 0) { i = 6; } - else if (strcmp(mon, "Jul") == 0) { i = 7; } - else if (strcmp(mon, "Aug") == 0) { i = 8; } - else if (strcmp(mon, "Sep") == 0) { i = 9; } - else if (strcmp(mon, "Oct") == 0) { i = 10; } - else if (strcmp(mon, "Nov") == 0) { i = 11; } - else if (strcmp(mon, "Dec") == 0) { i = 12; } - return i; -} - -// Fuction to initialize date type -// Assumes that argument is a string -// in the format 'mmm dd, yyyy' or 'mmm yyyy' -// or NULL for empty initialization -date new_date(string *fmt) -{ - date d; - if (fmt != NULL) { - uint8_t i = 0; - string aux; - // If the format is 'mmm dd, yyyy' - if (strlen(fmt->buf) > 10) { - // parsing day - i = fmt->find(fmt, ",") - 4; - aux = fmt->substr(fmt, 4, i); - d.day = aux.to_int(&aux); - aux.delete(&aux); - - // parsing month - aux = fmt->substr(fmt, 0, 3); - strcpy(d.month, aux.buf); - aux.delete(&aux); - - // parsing year - i = fmt->find(fmt, ",") + 2; - aux = fmt->substr(fmt, i, (fmt->length(fmt) - i)); - d.year = aux.to_int(&aux); - aux.delete(&aux); - } else { // Assuming format is 'mmm yyyy' - // no day provided in this format - d.day = 0; - - // parsing month - i = fmt->find(fmt, " "); - aux = fmt->substr(fmt, 0, i); - strcpy(d.month, aux.buf); - aux.delete(&aux); - - // parsing year - aux = fmt->substr(fmt, (i + 1), fmt->length(fmt) - (i + 1)); - d.year = aux.to_int(&aux); - aux.delete(&aux); - } - // parsing value - unsigned mon = strmon_to_int(d.month); - d.value = ((d.year * 10000) + (mon * 100) + d.day); - } else { - d.day = 0; - strcpy(d.month, "mmm"); - d.year = 0; - d.value = 0; - } - return d; -} - -// Function to initialize -// an 'empty' game struct -game empty_game(void) -{ - game g; - g.app_id = 0; - g.name = new_string(""); - g.release_date = new_date(NULL); - g.owners = new_string(""); - g.age = 0; - g.price = 0.0f; - g.dlcs = 0; - g.languages = new_strarr(NULL, 0); - g.website = new_string(""); - g.windows = false; - g.mac = false; - g.linux_ = false; - g.upvotes = 0.0f; - g.avg_pt = 0; - g.developers = new_string(""); - g.genres = new_strarr(NULL, 0); - return g; -} - -// Function to initialize a new game with -// the retrievd data in the string array -game new_game(string *s_arr) -{ - game g; - if (s_arr != NULL) { - // App id - g.app_id = atoi(s_arr[0].buf); - // Name - g.name = new_string(s_arr[1].buf); - // Release date - g.release_date = new_date(s_arr + 2); - // Owners - g.owners = new_string(s_arr[3].buf); - // Age, Price, DLCs - g.age = atoi(s_arr[4].buf); - g.price = atof(s_arr[5].buf); - g.dlcs = atoi(s_arr[6].buf); - // Languages - // If string is not empty then splits it into a string array - if (strcmp(s_arr[7].buf, "[]") != 0) { - string tmp = s_arr[7].substr(s_arr + 7, 2, strlen(s_arr[7].buf) - 4); - tmp.replace(&tmp, "', '", "|"); - g.languages = tmp.split(&tmp, "|"); - tmp.delete(&tmp); - } else { - g.languages = new_strarr(NULL, 0); - string *tmp = realloc(g.languages.src, sizeof(string)); - if (tmp != NULL) { - tmp[0] = new_string(""); - g.languages.src = tmp; - g.languages.length = 1; - } - } - // Website - g.website = new_string(s_arr[8].buf); - // Windows, Mac, Linux - g.windows = (strcmp(s_arr[9].buf, "True") == 0) ? true : false; - g.mac = (strcmp(s_arr[10].buf, "True") == 0) ? true : false; - g.linux_ = (strcmp(s_arr[11].buf, "True") == 0) ? true : false; - // Upvotes - float up_votes = atof(s_arr[12].buf); - float down_votes = atof(s_arr[13].buf); - g.upvotes = (up_votes / ((up_votes + down_votes) / 100)); - // Avg pt - g.avg_pt = atoi(s_arr[14].buf); - // Developers - g.developers = new_string(s_arr[15].buf); - // Genres - // If string is not empty and has a ',' then splits it into a string array - if ((strcmp(s_arr[16].buf, "") != 0) && - (s_arr[16].find(s_arr + 16, ",") != strlen(s_arr[16].buf))) { - g.genres = s_arr[16].split(s_arr + 16, ","); - } else { - g.genres = new_strarr(NULL, 0); - string *tmp = realloc(g.genres.src, sizeof(string)); - if (tmp != NULL) { - tmp[0] = new_string(s_arr[16].buf); - g.genres.src = tmp; - g.genres.length = 1; - } - } - } else g = empty_game(); - return g; -} - -// function to deallocates all -// the heap variables inside the game struct -void game_delete(game *g) -{ - if (g != NULL) { - g->name.delete(&g->name); - g->owners.delete(&g->owners); - g->languages.delete(&g->languages); - g->website.delete(&g->website); - g->developers.delete(&g->developers); - g->genres.delete(&g->genres); - } -} - -// Receives a char array that contains -// the data of the game strut in a csv format -// parses it and returns a game data structure -game chararr_to_game(char *ch_arr) -{ - game g; - if (ch_arr != NULL) { - // Initializing static array of strings - // where each index will be a field of the game data struct - string s_arr[GAME_FIELDS_SIZE]; - for (int i = 0; i < GAME_FIELDS_SIZE; i++) { - s_arr[i] = new_string(NULL); - } - - // Initializing variables for the split algorithm - string aux = new_string(NULL); - aux.buf = malloc(sizeof(char) * MAX_LINE_SIZE); - size_t ch_arr_len = strlen(ch_arr), s_arr_i = 0, aux_i = 0; - bool is_str_lit = false; - - // Loop to split each csv cell into a string - // and adds it to the array of strings - for (size_t i = 0; i < ch_arr_len; i++) { - if (ch_arr[i] == '"') { - is_str_lit = (is_str_lit ? false : true); - } else if (ch_arr[i] == ',' && !is_str_lit) { - aux.buf[aux_i] = '\0'; - s_arr[s_arr_i].buf = malloc(sizeof(char) * (strlen(aux.buf) + 1)); - strcpy(s_arr[s_arr_i].buf, aux.buf); - s_arr_i++; aux_i = 0; - } else { - aux.buf[aux_i++] = ch_arr[i]; - } - } - // Adding last string cell to the array - aux.buf[aux_i] = '\0'; - s_arr[s_arr_i].buf = malloc(sizeof(char) * (strlen(aux.buf) + 1)); - strcpy(s_arr[s_arr_i].buf, aux.buf); - aux.delete(&aux); - // Creating game with parsed data - g = new_game(s_arr); - - // Deallocating the string array - for (size_t i = 0; i < GAME_FIELDS_SIZE; i++) { - free(s_arr[i].buf); - } - } else g = empty_game(); - return g; -} - -// Converts avg_pt (int with amount of minutes) -// to a string in format '[x]h [y]m' returns -// a string with 'null' if avg_pt equals zero -char *avgpt_to_chararr (unsigned avg_pt) -{ - char *c_arr = calloc(16, sizeof(char)); - if (avg_pt != 0) { - unsigned h = avg_pt / 60; - unsigned m = avg_pt % 60; - - if (h != 0 && m != 0) { - snprintf(c_arr, 16, "%dh %dm", h, m); - } else if (h != 0) { - snprintf(c_arr, 16, "%dh", h); - } else if (m != 0) { - snprintf(c_arr, 16, "%dm", m); - } - } else { - strcpy(c_arr, "null"); - } - return c_arr; -} - -// prints the game structure in the format -// as is specified in the assignment -void game_print(game *g) -{ - printf("%u %s %s/%d %s %u %.2f %u [", - g->app_id, g->name.buf, - g->release_date.month, - g->release_date.year, - g->owners.buf, g->age, - g->price, g->dlcs); - // languages - for (size_t i = 0; i < g->languages.length - 1; i++) - printf("%s, ", g->languages.src[i].buf); - char *aux = avgpt_to_chararr(g->avg_pt); - printf("%s] %s %s %s %s %.0f%% %s %s [", - g->languages.src[g->languages.length - 1].buf, g->website.buf, - (g->windows ? "true" : "false"), (g->mac ? "true" : "false"), - (g->linux_ ? "true" : "false"), g->upvotes, aux, g->developers.buf); - free(aux); - // genres - for (size_t i = 0; i < g->genres.length - 1; i++) - printf("%s, ", g->genres.src[i].buf); - printf("%s]\n", g->genres.src[g->genres.length - 1].buf); -} - -// Search for the matching 'app_id' and read the game data -// from the file 'games.csv' then adds the game to the games array -void game_read_csv(game *games, size_t *ids, size_t ids_len) -{ - // Handling file opening - FILE *f = fopen(FILE_PATH, "r"); - assert__(f != NULL) { - fprintf(stderr, "Failed to open '%s'\n%s", FILE_PATH, - "Hint: Try adding or removing a '/' in front (OS Dependent)\n"); - } - - char line[MAX_LINE_SIZE + 1]; - size_t cur_id = 0; - // Searching the desired id then calling the parser function - for (size_t i = 0; i < ids_len; i++) { - while (cur_id != ids[i]) { - // reads line from file - fgets(line, MAX_LINE_SIZE, f); - // checking if is a reserved char to then trim it - if (line[strlen(line) - 2] < ' ') line[strlen(line) - 2] = '\0'; - else if (line[strlen(line) - 1] < ' ') line[strlen(line) - 1] = '\0'; - // atoi will only parse the beginning of the string ;) - cur_id = atoi(line); - } - rewind(f); // Resets file pointer to the beginning of the file - games[i] = chararr_to_game(line); // calling parser function - } - fclose(f); // closing the file -} - -// ------------------------------------ main ------------------------------------ // - -// Uses strcmp to check if -// input string equals 'FIM' -// meaning end of input -bool is_fim(char *c_arr) -{ - return (strcmp(c_arr, "FIM") == 0); -} - -// The main function contains the solution to -// the second question of the assignment, which is -// to read 'n' lines of strings containing the -// desired IDs of games to be read from the file 'games.csv', -// parse the data, store it in a game struct already defined, -// and print all of them in a specified format. -int main(void) -{ - // game array - game games[MAX_GAMES]; - size_t games_sz = 0; - // input variables - char input[MAX_FIELD_SIZE ]; - size_t ids[MAX_GAMES]; - - // Reading input and converting to integer - // then adding it to the array of ids to be searched - fgets(input, MAX_LINE_SIZE, stdin); - input[strlen(input) - 1] = '\0'; - while (!is_fim(input)) { - ids[games_sz++] = atoi(input); - fgets(input, MAX_LINE_SIZE, stdin); - // checking if is a reserved char to then trim it - if (input[strlen(input) - 2] < ' ') input[strlen(input) - 2] = '\0'; - else if (input[strlen(input) - 1] < ' ') input[strlen(input) - 1] = '\0'; - } - // If the array of ids is not empty - if (games_sz > 0) { - // Calls function to read from file and populate array of games - game_read_csv(games, ids, games_sz); - - // Prints the games read and frees the heap allocated memory - for (size_t i = 0; i < games_sz; i++) { - game_print(games + i); - game_delete(games + i); - } - } - return 0; -} +// ------------------------------------------------------------------------------ // +// Author: Vinicius Gabriel dos Santos - https://github.com/ravixr +// Sep/2022 +// +// DESCRIPTION: +// In addition to the game data structure and +// the solution to the second question of the assignment, +// this file contains a basic implementation of a string type +// which was extensively used in the game data structure +// as well as in the solution algorithm. +// ------------------------------------------------------------------------------ // + +#include +#include +#include +#include +#include +#include + +#define GAME_FIELDS_SIZE 17 +#define MAX_FIELD_SIZE 500 +#define MAX_LINE_SIZE 1000 +#define MAX_GAMES 100 + +// If on windows remove first slash -> 'tmp/games.csv' +#define FILE_PATH "/tmp/games.csv" + +// Assert macro to print custom message when assertion fails +#define assert__(x) for (; !(x); assert(x)) + +// --------------------------- my_very_basic_string.h --------------------------- // + +typedef struct string_t string; + +typedef struct strarr_t strarr; + +struct string_t { + char *buf; + char (*char_at)(const string *, size_t); + int (*compare)(const string *, const string *); + void (*delete)(string *); + size_t (*find)(const string *, const char *); + size_t (*length)(const string *); + void (*replace)(string *, const char *, const char *); + strarr (*split)(const string *, const char *); + string (*substr)(const string *, size_t, size_t); + float (*to_float)(const string *); + int (*to_int)(const string *); + void (*trim)(string *); +}; + +struct strarr_t { + string *src; + size_t length; + void (*delete)(strarr *); +}; + +// string functions declaration +char str_char_at(const string *, size_t); +int str_compare(const string *, const string *); +void str_delete(string *); +size_t str_find(const string *, const char *); +size_t str_length(const string *); +void str_replace(string *, const char*, const char *); +string new_string(char *); +strarr str_split(const string *, const char *); +string str_substr(const string *, size_t, size_t); +float str_to_float(const string *); +int str_to_int(const string *); +void str_trim(string *); + +// strarr functions declaration +strarr new_strarr(string *, size_t); +void strarr_delete(strarr *); + +// --------------------------- my_very_basic_string.c --------------------------- // + +// Fuction to initialize string type +string new_string(char *src) +{ + string str; + if (src != NULL) { + if (strcmp(src, "") != 0) { + str.buf = malloc(sizeof(char) * (strlen(src) + 1)); + strcpy(str.buf, src); + } else { + str.buf = malloc(sizeof(char) * 5); + strcpy(str.buf, "null"); + } + } else str.buf = NULL; + str.char_at = &str_char_at; + str.compare = &str_compare; + str.delete = &str_delete; + str.find = &str_find; + str.replace = &str_replace; + str.length = &str_length; + str.split = &str_split; + str.substr = &str_substr; + str.to_float = &str_to_float; + str.to_int = &str_to_int; + str.trim = &str_trim; + return str; +} + +// Fuction to deallocate string type +void str_delete(string *self) +{ + free(self->buf); +} + +// Returns character present in the specified index of the string +// e.g: "foo" idx: 0 -> 'f' +char str_char_at(const string *self, size_t idx) +{ + // Macro to assert index is in bounds + assert__(idx < strlen(self->buf)) { + fprintf(stderr, "String index %ld is out of bounds\n", idx); + } + return self->buf[idx]; +} + +// Allows comparison between string type variables using strcmp in the raw data +int str_compare(const string *self, const string *another_str) +{ + return strcmp(self->buf, another_str->buf); +} + +// Searches the string for the first occurrence of the pattern specified. +// Returns the index position of the first character of the pattern +// or the length of the string if the pattern is not found +// e.g.: "foo bar", "bar" -> 4 | "foo bar", "baz" -> 7 +size_t str_find(const string *self, const char *lkf) +{ + size_t i = 0, + self_len = strlen(self->buf), + lkf_len = strlen(lkf); + + // Macro to assert pattern string is valid + assert__((strcmp(lkf, "") != 0) && (lkf_len <= self_len)) { + fprintf(stderr, "Pattern '%s' is invalid for the specified string\n", lkf); + } + + // Find algorithm + for (size_t j = 0; i < self_len; i++) { + if (self->buf[i] == lkf[j]) { + j++; + } else { + i-= j; j = 0; + } + if (j == lkf_len) { + i -= (j - 1); + break; + } + } + return i; +} + +// Returns the length of the string using strlen in the raw data +size_t str_length(const string *self) +{ + return strlen(self->buf); +} + +// Replaces all occurrences of specified pattern in the string with the new specified pattern +// if the string doesn't contains the pattern to be replaced the string is not changed +// e.g.: "foobar", "bar", "" -> "foo" | "foobar", "baz", "" -> "foobar" +void str_replace(string *self, const char *old_val, const char *new_val) +{ + // Saving useful lengths in variables + size_t old_len = strlen(self->buf), + nv_len = strlen(new_val), + ov_len = strlen(old_val); + + // Macro to assert given pattern is valid + assert__((strcmp(old_val, "") != 0) && (old_len >= ov_len)) { + fprintf(stderr, "Invalid pattern for argument 'old_val'\n"); + } + + // Calculating the max possible amount of patterns in the string + // then allocating an array to store their indexes + size_t idx_sz = (old_len / ov_len), + *idx = malloc(sizeof(size_t) * (idx_sz + 1)), + idx_i = 0, last_idx = 0, skip = 0; + + // Getting all starting indexes of where the pattern is found + string aux = new_string(NULL); + aux.buf = (self->buf); + while ((idx_i <= idx_sz) && (last_idx < old_len)) { + idx[idx_i] = str_find(&aux, old_val) + skip; + skip = idx[idx_i++] + ov_len; + aux.buf = (self->buf + skip); + last_idx = idx[idx_i - 1]; + } + + // Checking if the pattern is actually on the string + if (idx[0] != old_len) { + // Assuring 'idx_i' will not be 0 + idx_i > 1 ? (idx_i -= 1) : (idx_i = 1); + + // Calculating new length of the string then allocating + size_t new_len = (old_len + ((nv_len - ov_len) * idx_i)); + char *tmp = malloc(sizeof(char) * (new_len + 1)); + + // Main Replacement algorithm: copies old string char by char, + // when the index is equal to the range of the next found pattern + // starts copying the new pattern char by chat into the string + if (nv_len == 0) nv_len = 1; + for (size_t i = 0, j = 0, k = 0, l = 0; i < new_len;) { + if (k >= idx[l] && k < (idx[l] + ov_len)) { + if (strcmp(new_val, "") != 0) + tmp[i++] = new_val[j]; + j++; + if (j == nv_len) { + k += ov_len; + j = 0; l++; + } + } else tmp[i++] = self->buf[k++]; + } + tmp[new_len] = '\0'; // Adding null terminator in the new string + free(self->buf); // freeing old string + self->buf = tmp; // Pointing to new string + } + free(idx); // freeing array of indexes of the old string +} + +// Uses strtok to split the raw char array +// then build new strings with the splitted char arrays +// and bundle all of them in the strarr type +// e.g.: 'foo,bar' ',' -> ['foo', 'bar'] +strarr str_split(const string *self, const char *delim) +{ + char *str = malloc(sizeof(char) * (strlen(self->buf) + 1)); + strcpy(str, self->buf); + char *token = strtok(str, delim); + size_t count = 0; + strarr str_arr = new_strarr(NULL, 0); + string *tmp; + while(token != NULL) { + tmp = realloc(str_arr.src, sizeof(string) * (count + 1)); + if (tmp != NULL) { + tmp[count++] = new_string(token); + str_arr.src = tmp; + } + token = strtok(NULL, delim); + } + free(str); + free(token); + str_arr.length = count; + return str_arr; +} + +// Returns a new string that is a copy of the portion of the original string +// that starts at character position 'pos' and spans 'len' characters +// e.g.: "foo bar" pos: 4, len: 3 -> "bar" +string str_substr(const string *self, size_t pos, size_t len) +{ + // Macro to assert pos and len are in bounds + assert__((pos + len) <= strlen(self->buf)) { + fprintf(stderr, "String index %ld is out of bounds for '%s'\n", (pos + len), self->buf); + } + string substr = new_string(NULL); + substr.buf = malloc(sizeof(char) * (len + 1)); + for (size_t i = 0, j = 0; i < len; i++, j++) { + substr.buf[j] = self->buf[pos + i]; + } + substr.buf[len] = '\0'; + return substr; +} + +// Uses atof to convert string to float +float str_to_float(const string *self) +{ + return atof(self->buf); +} + +// Uses atoi to convert string to int +int str_to_int(const string *self) +{ + return atoi(self->buf); +} + +// Removes all spaces only from the beginning and ending of the string +// e.g.: " foo " -> "foo" | "foo bar" -> "foo bar" +void str_trim(string *self) +{ + size_t i = 0, j = (strlen(self->buf) - 1); + while (self->buf[i] == ' ' || self->buf[j] == ' ') { + if (self->buf[i] == ' ') i++; + if (self->buf[j] == ' ') j--; + } + string tmp = self->substr(self, i, (j - i) + 1); + free(self->buf); + self->buf = tmp.buf; +} + +// Fuction to initialize string array type +strarr new_strarr(string *src, size_t src_length) +{ + strarr str_arr; + if (src != NULL) + str_arr.src = src; + else { + src_length = (src_length > 0 ? src_length : 1); + str_arr.src = malloc(sizeof(string *)); + } + str_arr.length = src_length; + str_arr.delete = &strarr_delete; + return str_arr; +} + +// Fuction to deallocate string array type +void strarr_delete(strarr *self) +{ + for (size_t i = 0; i < self->length; i++) { + free(self->src[i].buf); + } + free(self->src); +} + +// ----------------------------------- game.h ----------------------------------- // + +typedef struct date_t date; + +struct date_t { + uint8_t day; + char month[4]; + unsigned year; + size_t value; +}; + +date new_date(string *); +unsigned strmon_to_int(const char *); + +typedef struct game_t game; + +struct game_t { + unsigned app_id; + string name; + date release_date; + string owners; + unsigned age; + float price; + unsigned dlcs; + strarr languages; + string website; + bool windows; + bool mac; + bool linux_; + float upvotes; + unsigned avg_pt; + string developers; + strarr genres; +}; + +game empty_game(void); +game new_game(string *); +game str_to_game(string *); +game chararr_to_game(char *); +void game_print(game *); +void game_read_csv(game *, size_t *, size_t); +char *avgpt_to_chararr (unsigned); + +// ----------------------------------- game.c ----------------------------------- // + +// Converts month abbreviated char array in format 'Mmm' +// to unsigned int, if unsuccessful returns 0 +// e.g.: "Aug" -> 8 | "aug" -> 0 +unsigned strmon_to_int(const char *mon) +{ + unsigned i = 0; + if (strcmp(mon, "Jan") == 0) { i = 1; } + else if (strcmp(mon, "Feb") == 0) { i = 2; } + else if (strcmp(mon, "Mar") == 0) { i = 3; } + else if (strcmp(mon, "Apr") == 0) { i = 4; } + else if (strcmp(mon, "May") == 0) { i = 5; } + else if (strcmp(mon, "Jun") == 0) { i = 6; } + else if (strcmp(mon, "Jul") == 0) { i = 7; } + else if (strcmp(mon, "Aug") == 0) { i = 8; } + else if (strcmp(mon, "Sep") == 0) { i = 9; } + else if (strcmp(mon, "Oct") == 0) { i = 10; } + else if (strcmp(mon, "Nov") == 0) { i = 11; } + else if (strcmp(mon, "Dec") == 0) { i = 12; } + return i; +} + +// Fuction to initialize date type +// Assumes that argument is a string +// in the format 'mmm dd, yyyy' or 'mmm yyyy' +// or NULL for empty initialization +date new_date(string *fmt) +{ + date d; + if (fmt != NULL) { + uint8_t i = 0; + string aux; + // If the format is 'mmm dd, yyyy' + if (strlen(fmt->buf) > 10) { + // parsing day + i = fmt->find(fmt, ",") - 4; + aux = fmt->substr(fmt, 4, i); + d.day = aux.to_int(&aux); + aux.delete(&aux); + + // parsing month + aux = fmt->substr(fmt, 0, 3); + strcpy(d.month, aux.buf); + aux.delete(&aux); + + // parsing year + i = fmt->find(fmt, ",") + 2; + aux = fmt->substr(fmt, i, (fmt->length(fmt) - i)); + d.year = aux.to_int(&aux); + aux.delete(&aux); + } else { // Assuming format is 'mmm yyyy' + // no day provided in this format + d.day = 0; + + // parsing month + i = fmt->find(fmt, " "); + aux = fmt->substr(fmt, 0, i); + strcpy(d.month, aux.buf); + aux.delete(&aux); + + // parsing year + aux = fmt->substr(fmt, (i + 1), fmt->length(fmt) - (i + 1)); + d.year = aux.to_int(&aux); + aux.delete(&aux); + } + // parsing value + unsigned mon = strmon_to_int(d.month); + d.value = ((d.year * 10000) + (mon * 100) + d.day); + } else { + d.day = 0; + strcpy(d.month, "mmm"); + d.year = 0; + d.value = 0; + } + return d; +} + +// Function to initialize +// an 'empty' game struct +game empty_game(void) +{ + game g; + g.app_id = 0; + g.name = new_string(""); + g.release_date = new_date(NULL); + g.owners = new_string(""); + g.age = 0; + g.price = 0.0f; + g.dlcs = 0; + g.languages = new_strarr(NULL, 0); + g.website = new_string(""); + g.windows = false; + g.mac = false; + g.linux_ = false; + g.upvotes = 0.0f; + g.avg_pt = 0; + g.developers = new_string(""); + g.genres = new_strarr(NULL, 0); + return g; +} + +// Function to initialize a new game with +// the retrievd data in the string array +game new_game(string *s_arr) +{ + game g; + if (s_arr != NULL) { + // App id + g.app_id = atoi(s_arr[0].buf); + // Name + g.name = new_string(s_arr[1].buf); + // Release date + g.release_date = new_date(s_arr + 2); + // Owners + g.owners = new_string(s_arr[3].buf); + // Age, Price, DLCs + g.age = atoi(s_arr[4].buf); + g.price = atof(s_arr[5].buf); + g.dlcs = atoi(s_arr[6].buf); + // Languages + // If string is not empty then splits it into a string array + if (strcmp(s_arr[7].buf, "[]") != 0) { + string tmp = s_arr[7].substr(s_arr + 7, 2, strlen(s_arr[7].buf) - 4); + tmp.replace(&tmp, "', '", "|"); + g.languages = tmp.split(&tmp, "|"); + tmp.delete(&tmp); + } else { + g.languages = new_strarr(NULL, 0); + string *tmp = realloc(g.languages.src, sizeof(string)); + if (tmp != NULL) { + tmp[0] = new_string(""); + g.languages.src = tmp; + g.languages.length = 1; + } + } + // Website + g.website = new_string(s_arr[8].buf); + // Windows, Mac, Linux + g.windows = (strcmp(s_arr[9].buf, "True") == 0) ? true : false; + g.mac = (strcmp(s_arr[10].buf, "True") == 0) ? true : false; + g.linux_ = (strcmp(s_arr[11].buf, "True") == 0) ? true : false; + // Upvotes + float up_votes = atof(s_arr[12].buf); + float down_votes = atof(s_arr[13].buf); + g.upvotes = (up_votes / ((up_votes + down_votes) / 100)); + // Avg pt + g.avg_pt = atoi(s_arr[14].buf); + // Developers + g.developers = new_string(s_arr[15].buf); + // Genres + // If string is not empty and has a ',' then splits it into a string array + if ((strcmp(s_arr[16].buf, "") != 0) && + (s_arr[16].find(s_arr + 16, ",") != strlen(s_arr[16].buf))) { + g.genres = s_arr[16].split(s_arr + 16, ","); + } else { + g.genres = new_strarr(NULL, 0); + string *tmp = realloc(g.genres.src, sizeof(string)); + if (tmp != NULL) { + tmp[0] = new_string(s_arr[16].buf); + g.genres.src = tmp; + g.genres.length = 1; + } + } + } else g = empty_game(); + return g; +} + +// function to deallocates all +// the heap variables inside the game struct +void game_delete(game *g) +{ + if (g != NULL) { + g->name.delete(&g->name); + g->owners.delete(&g->owners); + g->languages.delete(&g->languages); + g->website.delete(&g->website); + g->developers.delete(&g->developers); + g->genres.delete(&g->genres); + } +} + +// Receives a char array that contains +// the data of the game strut in a csv format +// parses it and returns a game data structure +game chararr_to_game(char *ch_arr) +{ + game g; + if (ch_arr != NULL) { + // Initializing static array of strings + // where each index will be a field of the game data struct + string s_arr[GAME_FIELDS_SIZE]; + for (int i = 0; i < GAME_FIELDS_SIZE; i++) { + s_arr[i] = new_string(NULL); + } + + // Initializing variables for the split algorithm + string aux = new_string(NULL); + aux.buf = malloc(sizeof(char) * MAX_LINE_SIZE); + size_t ch_arr_len = strlen(ch_arr), s_arr_i = 0, aux_i = 0; + bool is_str_lit = false; + + // Loop to split each csv cell into a string + // and adds it to the array of strings + for (size_t i = 0; i < ch_arr_len; i++) { + if (ch_arr[i] == '"') { + is_str_lit = (is_str_lit ? false : true); + } else if (ch_arr[i] == ',' && !is_str_lit) { + aux.buf[aux_i] = '\0'; + s_arr[s_arr_i].buf = malloc(sizeof(char) * (strlen(aux.buf) + 1)); + strcpy(s_arr[s_arr_i].buf, aux.buf); + s_arr_i++; aux_i = 0; + } else { + aux.buf[aux_i++] = ch_arr[i]; + } + } + // Adding last string cell to the array + aux.buf[aux_i] = '\0'; + s_arr[s_arr_i].buf = malloc(sizeof(char) * (strlen(aux.buf) + 1)); + strcpy(s_arr[s_arr_i].buf, aux.buf); + aux.delete(&aux); + // Creating game with parsed data + g = new_game(s_arr); + + // Deallocating the string array + for (size_t i = 0; i < GAME_FIELDS_SIZE; i++) { + free(s_arr[i].buf); + } + } else g = empty_game(); + return g; +} + +// Converts avg_pt (int with amount of minutes) +// to a string in format '[x]h [y]m' returns +// a string with 'null' if avg_pt equals zero +char *avgpt_to_chararr (unsigned avg_pt) +{ + char *c_arr = calloc(16, sizeof(char)); + if (avg_pt != 0) { + unsigned h = avg_pt / 60; + unsigned m = avg_pt % 60; + + if (h != 0 && m != 0) { + snprintf(c_arr, 16, "%dh %dm", h, m); + } else if (h != 0) { + snprintf(c_arr, 16, "%dh", h); + } else if (m != 0) { + snprintf(c_arr, 16, "%dm", m); + } + } else { + strcpy(c_arr, "null"); + } + return c_arr; +} + +// prints the game structure in the format +// as is specified in the assignment +void game_print(game *g) +{ + printf("%u %s %s/%d %s %u %.2f %u [", + g->app_id, g->name.buf, + g->release_date.month, + g->release_date.year, + g->owners.buf, g->age, + g->price, g->dlcs); + // languages + for (size_t i = 0; i < g->languages.length - 1; i++) + printf("%s, ", g->languages.src[i].buf); + char *aux = avgpt_to_chararr(g->avg_pt); + printf("%s] %s %s %s %s %.0f%% %s %s [", + g->languages.src[g->languages.length - 1].buf, g->website.buf, + (g->windows ? "true" : "false"), (g->mac ? "true" : "false"), + (g->linux_ ? "true" : "false"), g->upvotes, aux, g->developers.buf); + free(aux); + // genres + for (size_t i = 0; i < g->genres.length - 1; i++) + printf("%s, ", g->genres.src[i].buf); + printf("%s]\n", g->genres.src[g->genres.length - 1].buf); +} + +// Search for the matching 'app_id' and read the game data +// from the file 'games.csv' then adds the game to the games array +void game_read_csv(game *games, size_t *ids, size_t ids_len) +{ + // Handling file opening + FILE *f = fopen(FILE_PATH, "r"); + assert__(f != NULL) { + fprintf(stderr, "Failed to open '%s'\n%s", FILE_PATH, + "Hint: Try adding or removing a '/' in front (OS Dependent)\n"); + } + + char line[MAX_LINE_SIZE + 1]; + size_t cur_id = 0; + // Searching the desired id then calling the parser function + for (size_t i = 0; i < ids_len; i++) { + while (cur_id != ids[i]) { + // reads line from file + fgets(line, MAX_LINE_SIZE, f); + // checking if is a reserved char to then trim it + if (line[strlen(line) - 2] < ' ') line[strlen(line) - 2] = '\0'; + else if (line[strlen(line) - 1] < ' ') line[strlen(line) - 1] = '\0'; + // atoi will only parse the beginning of the string ;) + cur_id = atoi(line); + } + rewind(f); // Resets file pointer to the beginning of the file + games[i] = chararr_to_game(line); // calling parser function + } + fclose(f); // closing the file +} + +// ------------------------------------ main ------------------------------------ // + +// Uses strcmp to check if +// input string equals 'FIM' +// meaning end of input +bool is_fim(char *c_arr) +{ + return (strcmp(c_arr, "FIM") == 0); +} + +// The main function contains the solution to +// the second question of the assignment, which is +// to read 'n' lines of strings containing the +// desired IDs of games to be read from the file 'games.csv', +// parse the data, store it in a game struct already defined, +// and print all of them in a specified format. +int main(void) +{ + // game array + game games[MAX_GAMES]; + size_t games_sz = 0; + // input variables + char input[MAX_FIELD_SIZE ]; + size_t ids[MAX_GAMES]; + + // Reading input and converting to integer + // then adding it to the array of ids to be searched + fgets(input, MAX_LINE_SIZE, stdin); + input[strlen(input) - 1] = '\0'; + while (!is_fim(input)) { + ids[games_sz++] = atoi(input); + fgets(input, MAX_LINE_SIZE, stdin); + // checking if is a reserved char to then trim it + if (input[strlen(input) - 2] < ' ') input[strlen(input) - 2] = '\0'; + else if (input[strlen(input) - 1] < ' ') input[strlen(input) - 1] = '\0'; + } + // If the array of ids is not empty + if (games_sz > 0) { + // Calls function to read from file and populate array of games + game_read_csv(games, ids, games_sz); + + // Prints the games read and frees the heap allocated memory + for (size_t i = 0; i < games_sz; i++) { + game_print(games + i); + game_delete(games + i); + } + } + return 0; +} From 38ff107e6b718b007cf770c1133c2178244f7fe6 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:22:16 -0300 Subject: [PATCH 12/13] Update - README --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4f7a869..40da904 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ -# AEDII +# 💻 AEDS II Repositório de códigos da disciplina de Algoritmos e Estrutura de Dados II -## Ajuda +## ❓ Ajuda +[Guia com os principais comandos](fonte/ajuda/README.md) -[Readme.md com os principais comandos.](fonte/ajuda/README.md) - -## fonte - -## labs -Ativdades dos laboratórios. +## 📁 Fonte +[Pasta com as bibliotecas usadas na disciplina](fonte/ajuda/java) -## tps +## ⚙️ Labs +[Pasta com os exercícios de treinamento do laboratório](fonte/ajuda/README.md) + + +## 🔥 TPS +[Pasta com os trabalhos práticos do laboratório](tps) From 3c666783cea0f51e1cb93e9a4d027a78f94f8fe7 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Mon, 17 Oct 2022 22:22:43 -0300 Subject: [PATCH 13/13] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40da904..66cb1ee 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Repositório de códigos da disciplina de Algoritmos e Estrutura de Dados II ## ⚙️ Labs -[Pasta com os exercícios de treinamento do laboratório](fonte/ajuda/README.md) +[Pasta com os exercícios de treinamento do laboratório](labs) ## 🔥 TPS