0

Help. Isogram Detector Challenge.

I'm suprisingly confused on what's the error. The last 'for loop' for comparing letters seems to be empty, hence, showing empty or 'no output' message. Please check my code: https://www.sololearn.com/coach/83?ref=app

11th Jul 2024, 1:57 PM
Pat
4 Antworten
+ 1
Gulshan Mahawar thanks for your big help. I passed all test cases except test #3 which is hidden. Please see revised code: #include <iostream> #include <string> using namespace std; int main() { string word; cin>>word; //get size of word size_t char_len = word.length(); char arr_ch[char_len]; //convert and store string into char for(int i=0;i<=char_len;i++){ arr_ch[i] = word[i]; } bool flag = false; //check for isogram/repeating letters for(int i=0;i<=char_len;i++){ for(int j=0;j<=char_len;j++){ //compare letters if(arr_ch[j]==arr_ch[j+1]){ flag = true; } } } //return bool value into text cout<<boolalpha<<flag; return 0; }
11th Jul 2024, 6:10 PM
Pat
0
Oops. Sorry, I wasn't aware. Here's the code: #include <iostream> #include <string> using namespace std; int main() { string word; cin>>word; char arr_ch[word.length()]; //convert and store string into char for(int i=0;i<=word.length();i++){ arr_ch[i] = word[i]; } //check if char array contains string /*for(int i=0;i<=word.length();i++){ cout<<arr_ch[i]; }*/ bool flag = 0; //check for isogram/repeating letters for(int i=0;i<=word.length();i++){ //compare letters if(arr_ch[i]==arr_ch[i+1]){ //no output. why? cout<<arr_ch[i]; //flag=1; } } /*string isogram; if(flag==1){ isogram = "false"; }else{ isogram = "true"; } cout<<isogram;*/ return 0; }
11th Jul 2024, 2:33 PM
Pat
0
It worked like a charm. Thank you very much for your detailed explanation and for revising the code.
11th Jul 2024, 6:59 PM
Pat
0
import pygame import random # Initialize Pygame pygame.init() # Screen dimensions SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # Player attributes player_size = 50 player_color = BLACK player_x = 50 player_y = SCREEN_HEIGHT - player_size - 10 player_velocity = 5 # Obstacle attributes obstacle_width = 50 obstacle_height = 50 obstacle_color = RED obstacle_velocity = 5 # Set up the display screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Endless Runner") # Function to create obstacles def create_obstacle(): return [SCREEN_WIDTH, SCREEN_HEIGHT - obstacle_height - 10] # Game loop running = True clock = pygame.time.Clock() obstacles = [create_obstacle()] while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Move the player keys = pygame.key.get_pressed() if keys[pygame.K_UP] and player_y > 0: player_y -= player_v
11th Jul 2024, 10:47 PM
Ineji John
Ineji John - avatar