#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,count=0;
cin>>n;
string s;
for(int i=0;i<n;i++){
cin>>s[i];
}
for(int i=0;i<n;i++){
int predir=s[(i-1+n)%n]-'0';
int nextdir=s[(i+1)%n]-'0';
if(predir!=nextdir){
continue;
}
else{
if(predir==0&&s[i]=='0'){s[i]=1+'0';count++;}
if(predir==1&&s[i]=='1') {s[i]='0';count++;}
}
}
cout<<count<<endl;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef struct LNode{
int data;
LNode* next;
}LNode, *LinkList;
//bool Initlink(LNode& l) {
//l = (LNode*)malloc(sizeof(LNode));
//l->next = NULL;
//return true;
//}
LinkList tailLink(int n) { //尾插法
LinkList L = new LNode;
L->data = 9999;
L->next = NULL;
LNode* p, * r;
int number;
r = L;
for (int i = 0; i < n; i++) {
p = new LNode;
cin >> number;
p->data = number;
p->next = NULL;
r->next = p;
r = p;
}
return L;
}
LinkList headLink(int n) { //头插法
LinkList L = new LNode;
L->data = 9999;
L->next = NULL;
LNode* p;
int number;
for (int i = 0; i < n; i++) {
p = new LNode;
cin >> number;
p->data = number;
p->next = L->next;
L->next = p;
}
return L;
}
void printList(LinkList L) {
LNode* p;
p = L->next; //跳过头节点
while (p) {
cout << p->data << " ";
p = p->next;
}
cout << endl;
}
void reverseList(LinkList L) { //原地翻转
if (L == NULL) return;
else {
LNode *p, *r;
p = L->next; //新链表
L->next = NULL;
while (p != NULL) { //头插法把剩下的节点插进去
r = p->next;
p->next = L->next;
L->next = p;
p = r;
}
}
}
int main() {
int n;
cin >> n;
LinkList L= headLink(n);
printList(L);
reverseList(L);
printList(L);
return 0;
}
#include<iostream>
using namespace std;
const int MAX_SIZE = 10010;
class Stack {
private:
int data[MAX_SIZE];
int topIndex;
public:
Stack() {
topIndex = -1;
}
//入栈
void push(int num) {
if (full()) {
cout << "The Stack is full" << endl;
}
else {
data[++topIndex] = num;
}
}
//出栈
void pop() {
if (empty()) {
cout << "The Stack is empty" << endl;
}
else {
topIndex--;
}
}
//判空
bool empty() {
return topIndex == -1;
}
//判满
bool full() {
return topIndex == MAX_SIZE - 1;
}
//返回栈顶元素
int query() {
return data[topIndex];
}
};
int main() {
Stack s;
int n, num;
string ml;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ml;
if (ml == "push") {
cin >> num;
s.push(num);
}
else if (ml == "pop")
s.pop();
else if (ml == "empty") {
if (s.empty()) cout << "YES" << endl;
else cout << "NO" << endl;
}
else cout << s.query() << endl;
}
return 0;
}
#include<iostream>
using namespace std;
bool f(int num) {
for (int i = num - 1; i > num / 2; i--)
{
if (num % i == 0) return false;
}
return true;
}
int main() {
int i = 101, count=0;
for (; i < 200; i++) {
if (f(i)) {
count++;
cout << i << " ";
}
}
return 0;
}
using namespace std;
int main()
{
int n,count=0;
cin>>n;
string s;
for(int i=0;i<n;i++){
cin>>s[i];
}
for(int i=0;i<n;i++){
int predir=s[(i-1+n)%n]-'0';
int nextdir=s[(i+1)%n]-'0';
if(predir!=nextdir){
continue;
}
else{
if(predir==0&&s[i]=='0'){s[i]=1+'0';count++;}
if(predir==1&&s[i]=='1') {s[i]='0';count++;}
}
}
cout<<count<<endl;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef struct LNode{
int data;
LNode* next;
}LNode, *LinkList;
//bool Initlink(LNode& l) {
//l = (LNode*)malloc(sizeof(LNode));
//l->next = NULL;
//return true;
//}
LinkList tailLink(int n) { //尾插法
LinkList L = new LNode;
L->data = 9999;
L->next = NULL;
LNode* p, * r;
int number;
r = L;
for (int i = 0; i < n; i++) {
p = new LNode;
cin >> number;
p->data = number;
p->next = NULL;
r->next = p;
r = p;
}
return L;
}
LinkList headLink(int n) { //头插法
LinkList L = new LNode;
L->data = 9999;
L->next = NULL;
LNode* p;
int number;
for (int i = 0; i < n; i++) {
p = new LNode;
cin >> number;
p->data = number;
p->next = L->next;
L->next = p;
}
return L;
}
void printList(LinkList L) {
LNode* p;
p = L->next; //跳过头节点
while (p) {
cout << p->data << " ";
p = p->next;
}
cout << endl;
}
void reverseList(LinkList L) { //原地翻转
if (L == NULL) return;
else {
LNode *p, *r;
p = L->next; //新链表
L->next = NULL;
while (p != NULL) { //头插法把剩下的节点插进去
r = p->next;
p->next = L->next;
L->next = p;
p = r;
}
}
}
int main() {
int n;
cin >> n;
LinkList L= headLink(n);
printList(L);
reverseList(L);
printList(L);
return 0;
}
#include<iostream>
using namespace std;
const int MAX_SIZE = 10010;
class Stack {
private:
int data[MAX_SIZE];
int topIndex;
public:
Stack() {
topIndex = -1;
}
//入栈
void push(int num) {
if (full()) {
cout << "The Stack is full" << endl;
}
else {
data[++topIndex] = num;
}
}
//出栈
void pop() {
if (empty()) {
cout << "The Stack is empty" << endl;
}
else {
topIndex--;
}
}
//判空
bool empty() {
return topIndex == -1;
}
//判满
bool full() {
return topIndex == MAX_SIZE - 1;
}
//返回栈顶元素
int query() {
return data[topIndex];
}
};
int main() {
Stack s;
int n, num;
string ml;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ml;
if (ml == "push") {
cin >> num;
s.push(num);
}
else if (ml == "pop")
s.pop();
else if (ml == "empty") {
if (s.empty()) cout << "YES" << endl;
else cout << "NO" << endl;
}
else cout << s.query() << endl;
}
return 0;
}
#include<iostream>
using namespace std;
bool f(int num) {
for (int i = num - 1; i > num / 2; i--)
{
if (num % i == 0) return false;
}
return true;
}
int main() {
int i = 101, count=0;
for (; i < 200; i++) {
if (f(i)) {
count++;
cout << i << " ";
}
}
return 0;
}
全部评论
相关推荐
点赞 评论 收藏
分享